Skip to content
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

Merged
merged 1 commit into from
Dec 4, 2023
Merged

Conversation

timj-hh
Copy link
Contributor

@timj-hh timj-hh commented Dec 1, 2023

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

  • Adds a new 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 in agent module, so there is no functional change introduced. Custom formatters now consume this Config attribute rather than the direct time format.
  • New setter functions have been added to modify the Config struct for consumer facing logger config
  • SetTimestampFormat: Set the logger timestamp format. time.Format() will accept a time format struct, or something custom such as SetConfigLogFile.
  • SetConfigMaxFileSizeMB: Set the max file size of the logger before log rotation
  • SetConfigLogFormat: 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 and TestJSONFormat_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.

@timj-hh timj-hh marked this pull request as ready for review December 1, 2023 23:03
@timj-hh timj-hh requested a review from a team as a code owner December 1, 2023 23:03
Copy link
Contributor

@JoseVillalta JoseVillalta left a 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) {
Copy link
Contributor

@amogh09 amogh09 Dec 4, 2023

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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.

@timj-hh timj-hh merged commit 0869d3a into aws:dev Dec 4, 2023
7 checks passed
@danehlim danehlim mentioned this pull request Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants