Skip to content

Commit

Permalink
Initialize the interval trigger
Browse files Browse the repository at this point in the history
Without lastRotate initialized an interval trigger
will always trigger a rotation the first time its
callback is executed.
  • Loading branch information
nicholasberlin committed Dec 3, 2024
1 parent fea0092 commit 1db533b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion file/rotator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions file/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func newIntervalTrigger(interval time.Duration, clock clock) trigger {
return lastInterval != currentInterval
}
}

t.lastRotate = time.Now()
return &t
}

Expand Down

0 comments on commit 1db533b

Please sign in to comment.