From 6c64d348ee78d7370da3570afbc4f8b2e8ed5754 Mon Sep 17 00:00:00 2001 From: "Lee E. Hinman" Date: Mon, 23 Oct 2023 12:44:34 -0500 Subject: [PATCH] [file] rotator purge fix only include files for consideration of purging that include the extension --- file/rotator.go | 2 +- file/rotator_test.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/file/rotator.go b/file/rotator.go index fed02b9e..bb0abb02 100644 --- a/file/rotator.go +++ b/file/rotator.go @@ -482,7 +482,7 @@ func (d *dateRotator) Rotate(reason rotateReason, rotateTime time.Time) error { } func (d *dateRotator) RotatedFiles() []string { - files, err := filepath.Glob(d.filenamePrefix + "*") + files, err := filepath.Glob(d.filenamePrefix + "*" + d.extension) if err != nil { if d.log != nil { d.log.Debugw("failed to list existing logs: %+v", err) diff --git a/file/rotator_test.go b/file/rotator_test.go index 0cc6d020..74a58960 100644 --- a/file/rotator_test.go +++ b/file/rotator_test.go @@ -134,6 +134,7 @@ func TestDailyRotation(t *testing.T) { logname + "-" + twoDaysAgo + "-1.ndjson", logname + "-" + twoDaysAgo + "-2.ndjson", logname + "-" + twoDaysAgo + "-3.ndjson", + logname + "-diagnostic-" + twoDaysAgo + ".zip", } for _, f := range files { @@ -153,26 +154,26 @@ func TestDailyRotation(t *testing.T) { Rotate(t, r) - AssertDirContents(t, dir, logname+"-"+yesterday+"-12.ndjson", logname+"-"+yesterday+"-13.ndjson") + AssertDirContents(t, dir, logname+"-"+yesterday+"-12.ndjson", logname+"-"+yesterday+"-13.ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") WriteMsg(t, r) today := time.Now().Format(file.DateFormat) - AssertDirContents(t, dir, logname+"-"+yesterday+"-12.ndjson", logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson") + AssertDirContents(t, dir, logname+"-"+yesterday+"-12.ndjson", logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") Rotate(t, r) - AssertDirContents(t, dir, logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson") + AssertDirContents(t, dir, logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") WriteMsg(t, r) - AssertDirContents(t, dir, logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson", logname+"-"+today+"-1.ndjson") + AssertDirContents(t, dir, logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson", logname+"-"+today+"-1.ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") for i := 0; i < (int(maxSizeBytes)/len(logMessage))+1; i++ { WriteMsg(t, r) } - AssertDirContents(t, dir, logname+"-"+today+"-1.ndjson", logname+"-"+today+"-2.ndjson", logname+"-"+today+"-3.ndjson") + AssertDirContents(t, dir, logname+"-"+today+"-1.ndjson", logname+"-"+today+"-2.ndjson", logname+"-"+today+"-3.ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") } // Tests the FileConfig.RotateOnStartup parameter