-
Notifications
You must be signed in to change notification settings - Fork 617
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
Generalize seelog config and add setters #4048
Conversation
93b7f40
to
acd4765
Compare
acd4765
to
ddcc514
Compare
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.
LGTM
|
||
// SetConfigMaxFileSizeMB sets the max file size of a log file | ||
// in Megabytes before the logger rotates to a new file. | ||
func SetConfigMaxFileSizeMB(maxSizeInMB float64) { |
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 existing SetLevel
function takes care of reloading the seelog config but the new setter functions do not. I understand that now there are multiple setter functions, and a user might want to call the setter functions and then trigger a (re)load manually by calling InitSeeLog
once but this breaks the current pattern that setter functions take care of reloading the configuration.
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 not make the new setter functions call reloadConfig
?
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.
Discussed offline that reloadConfig
doesn't help with reloading log format.
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.
Synced offline, Some setters will require a reload of the custom formatters, which is not something reloadConfig
does. If we are always calling InitSeeLog
after each setter anyways, the access pattern can be abstracted to call InitSeeLog
manually after modifying desired config attributes
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.
Let's update the descriptions of the new setter functions to say that InitSeeLog
needs to be called for the change to take effect.
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.
Can be done in a new PR.
Summary
This change generalizes the Seelog/global logger configuration. Currently, the timestamp format is hardcoded in, and it is unwieldy to change values such as the default output file, log format, etc. by hand as they are controlled by environment variables, and a logger
Config
struct.Implementation details
timestampFormat
field into the private logger Config struct. This will specify the timestamp format used by structured loggers (i.e. RFC 3339). A new default has been added to the value used inagent
module, so there is no functional change introduced. Custom formatters now consume this Config attribute rather than the direct time format.SetTimestampFormat
: Set the logger timestamp format. time.Format() will accept a time format struct, or something custom such asSetConfigLogFile
.SetConfigMaxFileSizeMB
: Set the max file size of the logger before log rotationSetConfigLogFormat
: Set the format for logging(logfmt or json)SetConfigLogFile
: Set the output file for logging.Testing
New tests cover the changes: yes
TestLogfmtFormat_Structured_Timestamp
andTestJSONFormat_Structured_Timestamp
have been introduced to test the ability to pass a custom time format. They will validate the correctness of a custom time format passed in. Existing tests verify that timestamp format remains consistent when untouched.Description for the changelog
Generalize seelog config and add setters
Does this PR include breaking model changes? If so, Have you added transformation functions?
No. Most of this PR adds setters, and what was abstracted has been replaced with a default used by the
agent
module.Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.