-
Notifications
You must be signed in to change notification settings - Fork 29
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
improvement: Automatically rotate log files per Palantir convention #560
base: develop
Are you sure you want to change the base?
Conversation
…ft-go-server into lfdo/lumberjack-rotate
defer ticker.Stop() | ||
for { | ||
// Rotate once at start. If there is no file, it is no op. | ||
if err := logger.Rotate(); err != nil { |
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 guess there's no way to restart the timer when the file is rotated due to MaxSize? We're going to end up with smaller-than-desired files if we have two uncoordinated thresholds
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 is no way unfortunately. The lumberjack logger doesn't expose the current file size nor when was it last rotated.
@@ -679,6 +683,11 @@ func (s *Server) Start() (rErr error) { | |||
} | |||
} | |||
|
|||
// initialize log flushers | |||
for _, logFlusher := range s.logFlushers { |
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.
Why bother accumulating these and launching them in *Server? Couldn't this just go periodicallyRotateLogFiles(ctx, logger, slsFilename)
in newDefaultLogOutputWriter?
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.
The rotation function stops if the context is cancelled and we only have a context in the main server function after all loggers are initialized. Basically we want the go routine to exit when the server is stopped.
Summary
Per Palantir convention, we should be rotating and compressing log files on a cadence. Audit logs rotate hourly while the rest rotate daily.
Testing
Tested locally by running the server with a shorter rotation interval and can attest log files are rotated correctly.
Changelog
==COMMIT_MSG==
Automatically rotate log files per Palantir convention
==COMMIT_MSG==
This change is