feat: customize logger config (#53)

This commit is contained in:
hn8
2021-07-15 12:33:48 -07:00
committed by GitHub
parent 4ce29799cf
commit 1ae7488fe3
+5 -5
View File
@@ -22,7 +22,7 @@ func GetLogger() *zap.Logger {
} }
// valid levels: debug, info, warn, error, fatal, panic // valid levels: debug, info, warn, error, fatal, panic
func initLogger(config zap.Config, level string) { func InitLogger(config zap.Config, level string, opts ...zap.Option) {
if level != "" { if level != "" {
lvl := zapcore.Level(0) lvl := zapcore.Level(0)
if err := lvl.UnmarshalText([]byte(level)); err == nil { if err := lvl.UnmarshalText([]byte(level)); err == nil {
@@ -30,21 +30,21 @@ func initLogger(config zap.Config, level string) {
} }
} }
// skip one level to remove this helper file // skip one level to remove this helper file
l, _ := config.Build(zap.AddCallerSkip(1)) l, _ := config.Build(append(opts, zap.AddCallerSkip(1))...)
wrappedLogger = l.Sugar() wrappedLogger = l.Sugar()
defaultLogger, _ = config.Build() defaultLogger, _ = config.Build(opts...)
ionLogger := zapr.NewLogger(defaultLogger) ionLogger := zapr.NewLogger(defaultLogger)
sfu.Logger = ionLogger sfu.Logger = ionLogger
buffer.Logger = ionLogger buffer.Logger = ionLogger
} }
func InitProduction(logLevel string) { func InitProduction(logLevel string) {
initLogger(zap.NewProductionConfig(), logLevel) InitLogger(zap.NewProductionConfig(), logLevel)
} }
func InitDevelopment(logLevel string) { func InitDevelopment(logLevel string) {
initLogger(zap.NewDevelopmentConfig(), logLevel) InitLogger(zap.NewDevelopmentConfig(), logLevel)
} }
func Debugw(msg string, keysAndValues ...interface{}) { func Debugw(msg string, keysAndValues ...interface{}) {