fix(logrotation): fix issue where all logs are kept in archive (#3465)

This commit is contained in:
Jonathan Rainville 2023-05-11 14:36:01 -04:00 committed by GitHub
parent fd05016c6e
commit bba7135fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -52,6 +52,11 @@ func OverrideRootLog(enabled bool, levelStr string, fileOpts FileOptions, termin
handler log.Handler handler log.Handler
) )
if fileOpts.Filename != "" { 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()) handler = FileHandlerWithRotation(fileOpts, log.LogfmtFormat())
} else { } else {
handler = log.StreamHandler(os.Stderr, log.TerminalFormat(terminal)) handler = log.StreamHandler(os.Stderr, log.TerminalFormat(terminal))