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

Use a single, non-replaceable default logger #24

Merged
merged 5 commits into from
Jan 12, 2022
Merged

Conversation

jonyoder
Copy link
Collaborator

@jonyoder jonyoder commented Jan 6, 2022

Connected to #22. This PR:

  • Removes the SetDefaultLogger method. Instead of replacing the default logger with a new reference, simply use the Set* methods to update the existing default logger as needed.
  • Adds the methods SetFormatter and Tracef to the logger interface.
  • Adds the method Tracef to the debug logger interface.
  • Adds a public global DefaultLoggerFactory that can be set in an init() method to provide the rslog package with a different default logger. If this is unset, rslog will automatically create its own factory and default logger. See root.go in the example command directory for an example.
  • Removes the logger interface's Copy method. We no longer support copying a logger since it makes SIGHUP support impossible.
  • Removes the logger interface's SetReportCaller method. Since logrus reports the first non-logrus line of code, this feature was useless since it always simply reported a line of code in the rslog package.
  • Updates the debug logger to use the underlying defaultLogger rather than copying an existing logger.
  • Updates the example command with a debug command and a new global --level flag.
  • Adds a Compare(l LogLevel) method to the LogLevel struct so you can compare log levels based on the underlying logrus values.

Using the example commands:

just build
./out/testapp debug --message="hi jonathan" --level=TRACE
./out/testapp debug --message="hi jonathan" --level=DEBUG
./out/testapp log --message="hi jonathan" --level=INFO
./out/testapp log --message="hi jonathan" --level=WARN

@marcosnav
Copy link
Contributor

We'll want to bump a new version of the package when this changes land. But before that, we also want to rename rslog/loggertest to rslog/rslogtest. It would be good to push both things in the same tag. 🙂

@jonyoder
Copy link
Collaborator Author

jonyoder commented Jan 6, 2022

I will make the change to rslogtest in this PR while I'm here.

@jonyoder
Copy link
Collaborator Author

jonyoder commented Jan 7, 2022

Also added one more commit that includes an example service you can run to prove that logger reconfiguration works: 72b5b6a.

@jonyoder
Copy link
Collaborator Author

@marcosnav @eduardocfalcao Are you ok with merging this one now?

@marcosnav
Copy link
Contributor

@marcosnav @eduardocfalcao Are you ok with merging this one now?

@jonyoder Yes, I'm okay with it :)

@jonyoder jonyoder merged commit 850117f into main Jan 12, 2022
@jonyoder jonyoder deleted the jon/singularity branch January 12, 2022 19:51
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.

4 participants