From bba7135fb7f33ed6fd1de66cc8d1273acbce2bb1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 11 May 2023 14:36:01 -0400 Subject: [PATCH] fix(logrotation): fix issue where all logs are kept in archive (#3465) --- logutils/override.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/logutils/override.go b/logutils/override.go index 7505bca20..22d73ce98 100644 --- a/logutils/override.go +++ b/logutils/override.go @@ -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))