fix(logrotation): fix issue where all logs are kept in archive (#3465)
This commit is contained in:
parent
fd05016c6e
commit
bba7135fb7
|
@ -52,6 +52,11 @@ func OverrideRootLog(enabled bool, levelStr string, fileOpts FileOptions, termin
|
|||
handler log.Handler
|
||||
)
|
||||
if fileOpts.Filename != "" {
|
||||
if fileOpts.MaxBackups == 0 {
|
||||
// Setting MaxBackups to 0 causes all log files to be kept. Even setting MaxAge to > 0 doesn't fix it
|
||||
// Docs: https://pkg.go.dev/gopkg.in/natefinch/lumberjack.v2@v2.0.0#readme-cleaning-up-old-log-files
|
||||
fileOpts.MaxBackups = 1
|
||||
}
|
||||
handler = FileHandlerWithRotation(fileOpts, log.LogfmtFormat())
|
||||
} else {
|
||||
handler = log.StreamHandler(os.Stderr, log.TerminalFormat(terminal))
|
||||
|
|
Loading…
Reference in New Issue