github.com/weedge/lib@v0.0.0-20230424045628-a36dcc1d90e4/log/define.go (about) 1 package log 2 3 import ( 4 "path/filepath" 5 6 "github.com/weedge/lib/log/tapper" 7 ) 8 9 var ( 10 defaultLogger = newConsoleLogger() 11 12 mainLogger *mainLog 13 bizLogger *bizLog 14 panicLogger *panicLog 15 accessLogger *accessLog 16 rpcLogger *rpcLog 17 ) 18 19 var ( 20 defaultLogConfFileName = "log.json" 21 ) 22 23 func createLogger(conf *LogConfig, projectName, defaultLogPath string) (err error) { 24 tapper.Project = projectName 25 for _, loggerConf := range conf.Logs { 26 if loggerConf.Path == "" { 27 loggerConf.Path = filepath.Join(defaultLogPath, projectName+"-"+loggerConf.Logger+".log") 28 } 29 if loggerConf.MinLevel == "" { 30 loggerConf.MinLevel = "info" 31 } 32 if loggerConf.Policy == "" { 33 loggerConf.Policy = "file" 34 } 35 switch loggerConf.Logger { 36 case "main": 37 mainLogger, err = newMainLogger(loggerConf, conf.RotateByHour) 38 case "biz": 39 bizLogger, err = newBizLogger(loggerConf, conf.RotateByHour) 40 case "panic": 41 panicLogger, err = newPanicLogger(loggerConf, conf.RotateByHour) 42 case "access": 43 accessLogger, err = newAccessLogger(loggerConf, conf.RotateByHour) 44 case "rpc": 45 rpcLogger, err = newRpcLogger(loggerConf, conf.RotateByHour) 46 } 47 } 48 49 return 50 }