2022-07-13 09:54:08 +08:00
|
|
|
|
# logging
|
|
|
|
|
|
2022-07-13 13:48:31 +08:00
|
|
|
|
日志组件
|
|
|
|
|
|
|
|
|
|
## 使用说明
|
|
|
|
|
|
|
|
|
|
日志组件封装了uber/zap,使用基本一致
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"git.hpds.cc/Component/logging"
|
|
|
|
|
|
2022-07-13 17:14:38 +08:00
|
|
|
|
"go.uber.org/zap/zap"
|
2022-07-13 13:48:31 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main(){
|
2022-07-13 17:14:38 +08:00
|
|
|
|
logger := LoadLoggerConfig()
|
2022-07-13 13:48:31 +08:00
|
|
|
|
logger.Info("this is a test log")
|
2022-07-13 17:14:38 +08:00
|
|
|
|
//也可以这样直接使用
|
|
|
|
|
|
|
|
|
|
logging.L().Info("this is a test log")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadLoggerConfig 加载日志配置
|
|
|
|
|
func LoadLoggerConfig() *logging.Logger {
|
|
|
|
|
return logging.NewLogger(
|
|
|
|
|
logging.SetPath("./log/"),
|
|
|
|
|
logging.SetPrefix(""),
|
|
|
|
|
logging.SetDevelopment(true),
|
|
|
|
|
logging.SetDebugFileSuffix(""),
|
|
|
|
|
logging.SetWarnFileSuffix(""),
|
|
|
|
|
logging.SetErrorFileSuffix(""),
|
|
|
|
|
logging.SetInfoFileSuffix(""),
|
|
|
|
|
logging.SetMaxAge(30),
|
|
|
|
|
logging.SetMaxBackups(100),
|
|
|
|
|
logging.SetMaxSize(100),
|
|
|
|
|
logging.SetLevel(logging.LogLevel["debug"]),
|
|
|
|
|
)
|
2022-07-13 13:48:31 +08:00
|
|
|
|
}
|
2022-07-13 17:14:38 +08:00
|
|
|
|
|
2022-07-13 13:48:31 +08:00
|
|
|
|
```
|