|
|
@@ -8,10 +8,11 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "github.com/runningwater/gohub/pkg/app"
|
|
|
"go.uber.org/zap"
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
|
+
|
|
|
+ "github.com/runningwater/gohub/pkg/app"
|
|
|
)
|
|
|
|
|
|
// Logger 全局日志对象
|
|
|
@@ -33,7 +34,7 @@ func Init(filename string, maxSize, maxBackup, maxAge int, compress bool, logTyp
|
|
|
Logger = zap.New(core,
|
|
|
zap.AddCaller(), // 调用文件和行号,内部使用 runtime.Caller
|
|
|
zap.AddCallerSkip(1), // 调用文件和行号,内部使用 runtime.Caller
|
|
|
- //zap.Development(), // 开发模式,堆栈跟踪
|
|
|
+ // zap.Development(), // 开发模式,堆栈跟踪
|
|
|
zap.AddStacktrace(zapcore.ErrorLevel), // 记录错误级别以上的堆栈信息
|
|
|
)
|
|
|
|
|
|
@@ -80,8 +81,8 @@ func customTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
|
|
func getLogWriter(filename string, maxSize, maxBackup, maxAge int, compress bool, logType string) zapcore.WriteSyncer {
|
|
|
// 如果配置了按日期记录日志,则使用按日期记录日志
|
|
|
if logType == "daily" {
|
|
|
- logname := time.Now().Format("2006-01-02") + ".log"
|
|
|
- filename = strings.Replace(filename, "logs.log", logname, 1)
|
|
|
+ logName := time.Now().Format("2006-01-02") + ".log"
|
|
|
+ filename = strings.Replace(filename, "logs.log", logName, 1)
|
|
|
}
|
|
|
|
|
|
// 滚动日志,详见 config/log.go
|
|
|
@@ -169,8 +170,8 @@ func Fatal(msg string, fields ...zap.Field) {
|
|
|
// DebugString 记录一条字符串类型的 debug 日志
|
|
|
//
|
|
|
// logger.DebugString("User", "name", "John")
|
|
|
-func DebugString(modeleName, name, msg string) {
|
|
|
- Logger.Debug(modeleName, zap.String(name, msg))
|
|
|
+func DebugString(moduleName, name, msg string) {
|
|
|
+ Logger.Debug(moduleName, zap.String(name, msg))
|
|
|
}
|
|
|
|
|
|
func InfoString(moduleName, name, msg string) {
|