Last active
September 29, 2020 01:30
-
-
Save zacscoding/0edc12651feef56a93d013c7a13fc2a3 to your computer and use it in GitHub Desktop.
logger to use package level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package logger | |
import ( | |
"go.uber.org/zap" | |
"go.uber.org/zap/zapcore" | |
) | |
var delegate *zap.SugaredLogger | |
func init() { | |
ec := zap.NewProductionEncoderConfig() | |
ec.EncodeTime = zapcore.ISO8601TimeEncoder | |
cfg := zap.Config{ | |
Encoding: "console", | |
EncoderConfig: ec, | |
Level: zap.NewAtomicLevelAt(zap.DebugLevel), | |
Development: false, | |
OutputPaths: []string{"stdout"}, | |
ErrorOutputPaths: []string{"stderr"}, | |
} | |
logger, err := cfg.Build() | |
if err != nil { | |
logger = zap.NewNop() | |
} | |
delegate = logger.Sugar() | |
} | |
func DefaultLogger() *zap.SugaredLogger { | |
return delegate | |
} | |
func Debug(args ...interface{}) { | |
delegate.Debug(args...) | |
} | |
func Info(args ...interface{}) { | |
delegate.Info(args...) | |
} | |
func Warn(args ...interface{}) { | |
delegate.Warn(args...) | |
} | |
func Error(args ...interface{}) { | |
delegate.Error(args...) | |
} | |
func DPanic(args ...interface{}) { | |
delegate.DPanic(args...) | |
} | |
func Panic(args ...interface{}) { | |
delegate.Panic(args...) | |
} | |
func Fatal(args ...interface{}) { | |
delegate.Fatal(args...) | |
} | |
func Debugf(template string, args ...interface{}) { | |
delegate.Debugf(template, args...) | |
} | |
func Infof(template string, args ...interface{}) { | |
delegate.Infof(template, args...) | |
} | |
func Warnf(template string, args ...interface{}) { | |
delegate.Warnf(template, args...) | |
} | |
func Errorf(template string, args ...interface{}) { | |
delegate.Errorf(template, args...) | |
} | |
func DPanicf(template string, args ...interface{}) { | |
delegate.DPanicf(template, args...) | |
} | |
func Panicf(template string, args ...interface{}) { | |
delegate.Panicf(template, args...) | |
} | |
func Fatalf(template string, args ...interface{}) { | |
delegate.Fatalf(template, args...) | |
} | |
func Debugw(msg string, keysAndValues ...interface{}) { | |
delegate.Debugw(msg, keysAndValues...) | |
} | |
func Infow(msg string, keysAndValues ...interface{}) { | |
delegate.Infow(msg, keysAndValues...) | |
} | |
func Warnw(msg string, keysAndValues ...interface{}) { | |
delegate.Warnw(msg, keysAndValues...) | |
} | |
func Errorw(msg string, keysAndValues ...interface{}) { | |
delegate.Errorw(msg, keysAndValues...) | |
} | |
func DPanicw(msg string, keysAndValues ...interface{}) { | |
delegate.Panicw(msg, keysAndValues...) | |
} | |
func Panicw(msg string, keysAndValues ...interface{}) { | |
delegate.Panicw(msg, keysAndValues...) | |
} | |
func Fatalw(msg string, keysAndValues ...interface{}) { | |
delegate.Fatalw(msg, keysAndValues...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment