about summary refs log tree commit diff stats
path: root/log
diff options
context:
space:
mode:
Diffstat (limited to 'log')
-rw-r--r--log/log.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/log/log.go b/log/log.go
index 730c2ef..63c6b23 100644
--- a/log/log.go
+++ b/log/log.go
@@ -64,7 +64,6 @@ func getLevelFromEnv() (zapcore.Level, error) {
 var atom zap.AtomicLevel
 
 func Configure(isProduction bool) *Logger {
-	var l *zap.Logger
 	atom = zap.NewAtomicLevel()
 	level, err := getLevelFromEnv()
 	if err != nil {
@@ -72,30 +71,32 @@ func Configure(isProduction bool) *Logger {
 	}
 	atom.SetLevel(level)
 
+	var filter zapfilter.FilterFunc
+	if debug := os.Getenv("DEBUG"); debug != "" {
+		filter = zapfilter.Any(zapfilter.MinimumLevel(level), zapfilter.ByNamespaces(debug))
+	} else {
+		filter = zapfilter.MinimumLevel(level)
+	}
+
+	var cfg zapcore.EncoderConfig
+	var enc zapcore.Encoder
 	if isProduction {
-		cfg := zap.NewProductionEncoderConfig()
-		cfg.TimeKey = ""
-		l = zap.New(zapcore.NewCore(zaplogfmt.NewEncoder(cfg), os.Stderr, atom))
+		cfg = zap.NewProductionEncoderConfig()
+		enc = zaplogfmt.NewEncoder(cfg)
 	} else {
-		cfg := prettyconsole.NewEncoderConfig()
-		cfg.TimeKey = ""
-		var filter zapfilter.FilterFunc
-		if debug := os.Getenv("DEBUG"); debug != "" {
-			filter = zapfilter.Any(zapfilter.MinimumLevel(level), zapfilter.ByNamespaces(debug))
-		} else {
-			filter = zapfilter.MinimumLevel(level)
-		}
-		l = zap.New(zapfilter.NewFilteringCore(
-			zapcore.NewCore(prettyconsole.NewEncoder(cfg), os.Stderr, zap.DebugLevel),
-			filter,
-		))
+		cfg = prettyconsole.NewEncoderConfig()
+		enc = prettyconsole.NewEncoder(cfg)
 	}
+	cfg.TimeKey = ""
+	log := zap.New(
+		zapfilter.NewFilteringCore(zapcore.NewCore(enc, os.Stderr, zap.DebugLevel), filter),
+	)
 
-	zap.ReplaceGlobals(l)
-	zap.RedirectStdLog(l)
+	zap.ReplaceGlobals(log)
+	zap.RedirectStdLog(log)
 
 	return &Logger{
-		logger: l.WithOptions(zap.AddCallerSkip(1)).Sugar(),
+		logger: log.WithOptions(zap.AddCallerSkip(1)).Sugar(),
 	}
 }