Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Feb 23, 2024
1 parent 0834502 commit 8024c7d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/types/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Check warning on line 55 in pkg/types/logging.go

View check run for this annotation

Codecov / codecov/patch

pkg/types/logging.go#L52-L55

Added lines #L52 - L55 were not covered by tests
}

log.SetLevel(cfgLevel)
if clearline {
logFormatter = &cslog.ClearLineFormatter{TextFormatter: log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}}

Check warning on line 59 in pkg/types/logging.go

View check run for this annotation

Codecov / codecov/patch

pkg/types/logging.go#L59

Added line #L59 was not covered by tests
} 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
Expand Down

0 comments on commit 8024c7d

Please sign in to comment.