This commit is contained in:
marco 2024-01-30 16:38:47 +01:00
parent 7a0bb6d7dc
commit fc1aa395fc

View file

@ -18,6 +18,8 @@ var LogOutput *lumberjack.Logger //io.Writer
var logLevel log.Level var logLevel log.Level
func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level, maxSize int, maxFiles int, maxAge int, compress *bool, forceColors bool) error { func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level, maxSize int, maxFiles int, maxAge int, compress *bool, forceColors bool) error {
clearline := false
switch cfgMode { switch cfgMode {
case "file": case "file":
_maxsize := 500 _maxsize := 500
@ -45,18 +47,23 @@ func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level
Compress: _compress, Compress: _compress,
} }
log.SetOutput(LogOutput) log.SetOutput(LogOutput)
logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}
case "stdout": case "stdout":
if cstty.IsTTY(os.Stderr.Fd()) { if cstty.IsTTY(os.Stderr.Fd()) {
logFormatter = &cslog.ClearLineFormatter{TextFormatter: log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}} clearline = true
} else {
logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}
} }
default: default:
return fmt.Errorf("log mode '%s' unknown", cfgMode) 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) log.SetFormatter(logFormatter)
return nil return nil