diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/log/log.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/internal/log/log.go b/internal/log/log.go index e16d7bb..f5b48b1 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -33,15 +33,28 @@ func Fatal(msg string, rest ...any) { logger.Fatalw(msg, rest...) } +func getLevelFromEnv() (zapcore.Level, error) { + if str, found := os.LookupEnv("LOG_LEVEL"); found { + l, err := zap.ParseAtomicLevel(str) + return l.Level(), err + } + return zap.InfoLevel, nil +} + func Configure(isProduction bool) { var l *zap.Logger + level, err := getLevelFromEnv() + if err != nil { + panic(err) + } if isProduction { cfg := zap.NewProductionEncoderConfig() cfg.TimeKey = "" - l = zap.New(zapcore.NewCore(zaplogfmt.NewEncoder(cfg), os.Stderr, zapcore.InfoLevel)) + l = zap.New(zapcore.NewCore(zaplogfmt.NewEncoder(cfg), os.Stderr, level)) } else { cfg := prettyconsole.NewConfig() cfg.EncoderConfig.TimeKey = "" + cfg.Level.SetLevel(level) l = zap.Must(cfg.Build()) } logger = l.WithOptions(zap.AddCallerSkip(1)).Sugar() |