Documentation
¶
Index ¶
- func DPanic(args ...interface{})
- func DPanicf(template string, args ...interface{})
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(template string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(template string, args ...interface{})
- func GinLogger() gin.HandlerFunc
- func GinRecovery(stack bool) gin.HandlerFunc
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func InitLogger()
- func Panic(args ...interface{})
- func Panicf(template string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(template string, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
func InitLogger()
func init() {
// 设置一些基本日志格式 具体含义还比较好理解,直接看zap源码也不难懂
encoder := zapcore.NewJSONEncoder(
zapcore.EncoderConfig{
TimeKey: "ts",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
FunctionKey: zapcore.OmitKey,
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.CapitalLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
})
core := zapcore.NewTee(
zapcore.NewCore(encoder, zapcore.AddSync(os.Stdout), zapcore.DebugLevel),
)
//core := zapcore.NewCore(encoder, zapcore.NewMultiWriteSyncer(os.Stdout, infoWriter, errorWriter), zapcore.DebugLevel)
ownLogger = zap.New(core, zap.AddCaller(), zap.AddCallerSkip(1)) // 需要传入 zap.AddCaller() 才会显示打日志点的文件名和行数
ownSugaredLogger = ownLogger.Sugar()
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.