Correctly use configured loglevel

This commit is contained in:
Torjus Håkestad 2021-11-06 01:51:19 +01:00
parent 056ac87eee
commit 9db21cb15d

View File

@ -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