package fslog import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" "gopkg.in/natefinch/lumberjack.v2" "io" "os" ) var log *Logger func init() { consoleEncoderConfig := zap.NewDevelopmentEncoderConfig() consoleEncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05") consoleEncoder = zapcore.NewConsoleEncoder(consoleEncoderConfig) jsonEncoderConfig := zap.NewProductionEncoderConfig() jsonEncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05") jsonEncoder = zapcore.NewJSONEncoder(jsonEncoderConfig) consoleSync = zapcore.AddSync(os.Stdout) outputSync = zapcore.AddSync(&lumberjack.Logger{ Filename: "logs/log", MaxSize: 1, MaxAge: 10, LocalTime: true, }) log = NewLogger() } // With 见 Logger.With func With(k string, v any) *Logger { return log.With(k, v) } // Info 见 Logger.Info func Info(msg string, vs ...any) { log.Info(msg, vs...) } // Debug 见 Logger.Debug func Debug(msg string, vs ...any) { log.Debug(msg, vs...) } // Warn 见 Logger.Warn func Warn(msg string, vs ...any) { log.Warn(msg, vs...) } // Error 见 Logger.Error func Error(vs ...any) { log.Error(vs...) } // Lv 见 Logger.Lv func Lv() Level { return Level(log.Lv().Level()) } // SetLv 见 Logger.SetLv func SetLv(lv Level) *Logger { log.SetLv(lv) return log } // NewFileOutput 见 Logger.NewFileOutput func NewFileOutput(opts ...FileOutputOpt) *Logger { log.NewFileOutput(opts...) return log } // NewOutput 见 Logger.NewOutput func NewOutput(writer io.Writer) *Logger { log.NewOutput(writer) return log } func Flush() { log.Flush() }