package logger import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" "os" ) func New() *zap.SugaredLogger { consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()) jsonEncoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()) consoleDebugging := zapcore.Lock(os.Stdout) lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { return lvl < zapcore.ErrorLevel }) highPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { return lvl >= zapcore.ErrorLevel }) consoleErrors := zapcore.Lock(os.Stderr) core := zapcore.NewTee( zapcore.NewCore(jsonEncoder, consoleErrors, highPriority), zapcore.NewCore(jsonEncoder, consoleDebugging, highPriority), zapcore.NewCore(consoleEncoder, consoleErrors, highPriority), zapcore.NewCore(consoleEncoder, consoleDebugging, lowPriority), ) logger := zap.New(core) defer func(logger *zap.Logger) { _ = logger.Sync() }(logger) sugaredLogger := logger.Sugar() return sugaredLogger }