From 1db533b21fcefa04d1eb401b7a059eab75497771 Mon Sep 17 00:00:00 2001 From: Nicholas Berlin Date: Tue, 3 Dec 2024 10:57:56 -0500 Subject: [PATCH] Initialize the interval trigger Without lastRotate initialized an interval trigger will always trigger a rotation the first time its callback is executed. --- file/rotator_test.go | 2 +- file/trigger.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/file/rotator_test.go b/file/rotator_test.go index 74a58960..8719b273 100644 --- a/file/rotator_test.go +++ b/file/rotator_test.go @@ -173,7 +173,7 @@ func TestDailyRotation(t *testing.T) { WriteMsg(t, r) } - AssertDirContents(t, dir, logname+"-"+today+"-1.ndjson", logname+"-"+today+"-2.ndjson", logname+"-"+today+"-3.ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") + AssertDirContents(t, dir, logname+"-"+today+".ndjson", logname+"-"+today+"-1.ndjson", logname+"-"+today+"-2.ndjson", logname+"-diagnostic-"+twoDaysAgo+".zip") } // Tests the FileConfig.RotateOnStartup parameter diff --git a/file/trigger.go b/file/trigger.go index 22c128a3..428f8354 100644 --- a/file/trigger.go +++ b/file/trigger.go @@ -138,6 +138,8 @@ func newIntervalTrigger(interval time.Duration, clock clock) trigger { return lastInterval != currentInterval } } + + t.lastRotate = time.Now() return &t }