Skip to content

Commit

Permalink
fix(logrotation): fix issue where all logs are kept in archive (#3465)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville authored May 11, 2023
1 parent fd05016 commit bba7135
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions logutils/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]#readme-cleaning-up-old-log-files
fileOpts.MaxBackups = 1
}
handler = FileHandlerWithRotation(fileOpts, log.LogfmtFormat())
} else {
handler = log.StreamHandler(os.Stderr, log.TerminalFormat(terminal))
Expand Down

0 comments on commit bba7135

Please sign in to comment.