How log rotation works in Timberjack
mainTimberjack supports several rotation triggers. Depending on your configuration, rotation can be triggered by file size, time intervals, specific clock times, or manual calls.
Rotation Triggers
- Size-Based: Triggered when a write operation would cause the file to exceed
MaxSize. The backup filename includes-size. - Time-Based (Interval): Triggered on the next write after
RotationIntervalhas elapsed since the last rotation. The backup filename includes-time. - Scheduled (Clock-Aligned): Triggered by a background goroutine at specific minutes (
RotateAtMinutes) or specific times (RotateAt). These use-timeas the reason. - Manual:
Logger.Rotate(): Forces immediate rotation.Logger.RotateWithReason(reason): Forces rotation and tags the file with a sanitized custom reason.
Filename Patterns
By default, rotated files follow the pattern: <name>-<timestamp>-<reason>.log.
If you set AppendTimeAfterExt: true, the pattern changes to: <name>.log-<timestamp>-<reason> (useful for shell TAB completion).
Example of custom reason:
If you call logger.RotateWithReason("reload-now v2"), the file might be named foo-2025-05-01T10-30-00.000-reload-now-v2.log.
// Manual rotation with a custom reason
_ = logger.RotateWithReason("reload-now v2")