From fc1aa395fc7af9f9e69cb7ec4462bb5996007b3c Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 30 Jan 2024 16:38:47 +0100 Subject: [PATCH] wip --- pkg/types/logging.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/types/logging.go b/pkg/types/logging.go index bb35ff2b1..a18d327e1 100644 --- a/pkg/types/logging.go +++ b/pkg/types/logging.go @@ -18,6 +18,8 @@ var LogOutput *lumberjack.Logger //io.Writer var logLevel log.Level func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level, maxSize int, maxFiles int, maxAge int, compress *bool, forceColors bool) error { + clearline := false + switch cfgMode { case "file": _maxsize := 500 @@ -45,18 +47,23 @@ func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level Compress: _compress, } log.SetOutput(LogOutput) - logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors} case "stdout": if cstty.IsTTY(os.Stderr.Fd()) { - logFormatter = &cslog.ClearLineFormatter{TextFormatter: log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}} - } else { - logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors} + clearline = true } default: return fmt.Errorf("log mode '%s' unknown", cfgMode) } - log.SetLevel(cfgLevel) + if clearline { + logFormatter = &cslog.ClearLineFormatter{TextFormatter: log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}} + } else { + logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors} + } + + // XXX: set logLevel for the other loggers (papi & co) + logLevel = cfgLevel + log.SetLevel(logLevel) log.SetFormatter(logFormatter) return nil