go.mod | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
logo/logo.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
util/common.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
go.mod
@@ -5,7 +5,7 @@ require ( basic.com/libgowrapper/sdkstruct.git v0.0.0-20191220011601-e0b3d1f0183c basic.com/valib/gogpu.git v0.0.0-20190711044327-62043b070865 github.com/amoghe/distillog v0.0.0-20180726233512-ae382b35b717 github.com/natefinch/lumberjack v2.0.0+incompatible github.com/spf13/viper v1.6.1 basic.com/valib/logger.git v0.0.0-20190928113028-4907b08c4159 github.com/olebedev/config v0.0.0-20190528211619-364964f3a8e4 gopkg.in/yaml.v2 v2.2.7 // indirect ) logo/logo.go
@@ -1,81 +1,50 @@ package logo import ( "github.com/amoghe/distillog" "github.com/natefinch/lumberjack" "basic.com/valib/logger.git" ) var loggers []distillog.Logger func Config(name string, size, backup, age int) { l := &lumberjack.Logger{ Filename: name, MaxSize: size, // megabytes MaxBackups: backup, MaxAge: age, // days } logger.Config(name, logger.DebugLevel) logger := distillog.NewStreamLogger("file", l) loggers = append(loggers, logger) distillog.SetOutput(l) } func ShowConsole() { l := distillog.NewStdoutLogger("console") loggers = append(loggers, l) } func Debugf(f string, v ...interface{}) { for _, l := range loggers { l.Debugf(f, v...) } logger.Debug(f, v) } func Debugln(v ...interface{}) { for _, l := range loggers { l.Debugln(v) } logger.Debug(v) } func Infof(f string, v ...interface{}) { for _, l := range loggers { l.Infof(f, v...) } logger.Info(f, v) } func Infoln(v ...interface{}) { for _, l := range loggers { l.Infoln(v) } logger.Info(v) } func Warningf(f string, v ...interface{}) { for _, l := range loggers { l.Warningf(f, v...) } logger.Warn(f, v) } func Warningln(v ...interface{}) { for _, l := range loggers { l.Warningln(v) } logger.Warn(v) } func Errorf(f string, v ...interface{}) { for _, l := range loggers { l.Errorf(f, v...) } logger.Error(f, v) } func Errorln(v ...interface{}) { for _, l := range loggers { l.Errorln(v) } logger.Error(v) } func Close() { for _, l := range loggers { l.Close() } } util/common.go
@@ -1,10 +1,12 @@ package util import ( "fmt" "io/ioutil" "os" "strings" "github.com/spf13/viper" "github.com/olebedev/config" ) // FillParams 填充MapParams @@ -41,22 +43,41 @@ func InitConfig() { const ( configFilePath = "/opt/vasystem/config/" configFileName = "pro" configFileType = "yaml" configFileName = "pro.yaml" LOGBASEPATH = "/data/disk1/valog/" ) viper.SetConfigType(configFileType) viper.SetConfigName(configFileName) viper.AddConfigPath(configFilePath) viper.AddConfigPath("./") configFilePaths := []string{ "/opt/vasystem/config/", "./", } LogFile = "./log/analysis-" if err := viper.ReadInConfig(); err == nil { var file []byte var err error var fileName string for _, v := range configFilePaths { fileName = v + configFileName file, err = ioutil.ReadFile(fileName) if err == nil { break } } if file == nil { fmt.Println("Read All Config Files Failed, Use Default, example LogFile ./log/analysis-'type'") return } yamlString := string(file) logPath := viper.GetString("LogBasePath") cfg, err := config.ParseYaml(yamlString) if err != nil { fmt.Println("Config Parse File: ", fileName, " Error: ", err) return } logPath, err := cfg.String("LogBasePath") if err == nil { if len(logPath) > 0 && IsFileExist(logPath) { if logPath[len(logPath)-1] == '/' { LogFile = logPath + "analysis-" @@ -69,5 +90,34 @@ } else if IsFileExist(LOGBASEPATH) { LogFile = LOGBASEPATH + "analysis-" } } // const ( // configFilePath = "/opt/vasystem/config/" // configFileName = "pro" // configFileType = "yaml" // LOGBASEPATH = "/data/disk1/valog/" // ) // viper.SetConfigType(configFileType) // viper.SetConfigName(configFileName) // viper.AddConfigPath(configFilePath) // viper.AddConfigPath("./") // LogFile = "./log/analysis-" // if err := viper.ReadInConfig(); err == nil { // logPath := viper.GetString("LogBasePath") // if len(logPath) > 0 && IsFileExist(logPath) { // if logPath[len(logPath)-1] == '/' { // LogFile = logPath + "analysis-" // } else { // LogFile = logPath + "/analysis-" // } // } else if IsFileExist(LOGBASEPATH) { // LogFile = LOGBASEPATH + "analysis-" // } // } else if IsFileExist(LOGBASEPATH) { // LogFile = LOGBASEPATH + "analysis-" // }