From 9db21cb15d266989fe78587f5bd66cd1ef43012b Mon Sep 17 00:00:00 2001 From: = Date: Sat, 6 Nov 2021 01:51:19 +0100 Subject: [PATCH] Correctly use configured loglevel --- cmd/apiary.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/apiary.go b/cmd/apiary.go index e6b8cfb..c61e90a 100644 --- a/cmd/apiary.go +++ b/cmd/apiary.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "os/signal" + "strings" "time" "github.com/coreos/go-systemd/daemon" @@ -264,7 +265,19 @@ func setupLoggers(cfg config.Config) *loggerCollection { logEncoderCfg := zap.NewProductionEncoderConfig() logEncoderCfg.EncodeCaller = func(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {} - level := zap.NewAtomicLevelAt(zap.InfoLevel) + var level zap.AtomicLevel + switch strings.ToUpper(cfg.Honeypot.LogLevel) { + case "INFO": + level = zap.NewAtomicLevelAt(zap.InfoLevel) + case "DEBUG": + level = zap.NewAtomicLevelAt(zap.DebugLevel) + case "WARN", "WARNING": + level = zap.NewAtomicLevelAt(zap.WarnLevel) + case "ERR", "ERROR": + level = zap.NewAtomicLevelAt(zap.WarnLevel) + default: + level = zap.NewAtomicLevelAt(zap.InfoLevel) + } logEncoderCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder logEncoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder logEncoderCfg.EncodeDuration = zapcore.StringDurationEncoder