From 764394d35050db4853b46c1f9129ad8bd881fd31 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jan 2024 17:10:27 +0800 Subject: [PATCH] feat: use different logger in debug mode --- common/logging/log.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/logging/log.go b/common/logging/log.go index 51267fe..e27a823 100644 --- a/common/logging/log.go +++ b/common/logging/log.go @@ -2,6 +2,7 @@ package logging import ( "context" + "github.com/samber/lo" "github.com/spf13/viper" "github.com/uptrace/opentelemetry-go-extra/otelzap" @@ -23,7 +24,7 @@ func NewLogger(ctx context.Context, viper *viper.Viper, options []zap.Option) (L ctx, span := tracer.Start(ctx, "logging.NewLogger") defer span.End() - zapLogger, err := zap.NewDevelopment(options...) + zapLogger, err := lo.If(viper.GetBool("debug"), zap.NewDevelopment).Else(zap.NewProduction)(options...) if err != nil { span.RecordError(err) otelzap.L().Ctx(ctx).Error("failed to create logger", zap.Error(err))