-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
logging: Switch from lumberjack
to timberjack
, add time-rolling options
#7244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Oh, fantastic! I didn't get the memo that a fork was worked on, we were waiting for someone to pick up the mantle. Will review soon. |
modules/logging/filewriter.go
Outdated
// Roll log file at fix time | ||
RollAt []string `json:"roll_at,omitempty` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand what the inputs are here. What are the values supposed to be? The godoc comment here should be fleshed out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answering my own question, it looks something like this in timberjack
RotateAt: []string{"00:00", "12:00"}, // Also rotate at 00:00 and 12:00 each day
@@ -109,6 +120,9 @@ type FileWriter struct { | |||
|
|||
// How many days to keep rolled log files. Default: 90 | |||
RollKeepDays int `json:"roll_keep_days,omitempty"` | |||
|
|||
// Rotated file will have format <logfilename>-<format>-<criterion>.log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should explain that the default from timberjack is:
// Optional. If unset or invalid, defaults to 2006-01-02T15-04-05.000 (with fallback warning)
Also mention that the <format>
must be a Go time compatible format described here https://pkg.go.dev/time#pkg-constants
// Roll log file at fix minutes | ||
RollAtMinutes []int `json:"roll_at_minutes,omitempty"` | ||
|
||
// Roll log file at fix time | ||
RollAt []string `json:"roll_at,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These godoc comments should cover some of the caveats mentioned in the timberjack README https://github.com/DeRuina/timberjack#%EF%B8%8F-rotation-notes--warnings (and eventually also in the Caddy website docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also subtleties like using either of RollAt/RollAtMinutes will use a background goroutine to trigger rotation, whereas RollInterval triggers a check on each log write whether the interval has been crossed and causes a rotation at that point (no goroutine).
lumberjack
to timberjack
add time-rolling options
lumberjack
to timberjack
add time-rolling optionslumberjack
to timberjack
, add time-rolling options
Lumberjack is unmaintained since 2 years.
A fork exists, Timberjack to replace it with more features.
This PR migrate to Timberjack and add support newest features, specially
RotateAt
options to allow to rotate log file base on date.Assistance Disclosure
No AI was used.