-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(log): require destination in calls to NewLogger #15262
Conversation
Prior to this change, NewLogger defaulted to sending logs to os.Stdout. This change updates the method to accept an io.Writer indicating where logs should go, so that consumers of the SDK could choose to send logs to stderr, as that is the more typical IO stream for logs. This is a temporary commit that changes the NewLogger signature but adds a NewLoggerToStdout function. The next commit will remove NewLoggerToStdout (preferring NewLogger(os.Stdout) and update the referenced version of the log module.
Prior to this change, log.NewLogger() was hardcoded to write to stdout. This is not always desirable: depending on where the logger is instantiated, it may need to be associated with a (*cobra.Command)'s out or err stream, or importers of the SDK may want to send logs to stderr instead of stdout. Additionally, this removes any ambiguity about where logs may go, when reading the code. Finally, this allows an easy migration to defaulting logs to stderr, should we choose to do that in the future.
Does not make it too verbose? |
A new logger should be instantiated once in a main function and propagated down. In tests, where we do instantiate many loggers, we have
No, logs go to stderr. stdout is for information that one would save to a file or pipe to another process. The choice to default logs to stdout is unusual.
The custom logger should be an exceptional case. |
Looks like I've missed a dependency update that I'll have to return to later. Putting this in draft mode until then. |
TIL, I am always used to pipe logs normally 🤔
Yeah, my bad. this makes sense! Just noticed CMT logger as well let you choose where it writes too |
There were CI failures due to depending on a mismatched pairing of the log module and the main SDK module.
I missed this earlier due to the linux build tag.
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!
Description
The previous implementation of
log.NewLogger
hardcoded the output toos.Stdout
. This change updates the signature fromNewLogger()
toNewLogger(dest io.Writer)
, so that callers have to be explicit whether they want logs to go to stdout, stderr, or somewhere else.This is useful particularly in
client/pruning.Cmd()
, where a new logger was instantiated; that logger is no longer hardcoded toos.Stdout
, but instead to a(*cobra.Command).OutOrStdout()
for more flexibility in tests that may use that command.Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
added!
to the type prefix if API or client breaking changetargeted the correct branch (see PR Targeting)provided a link to the relevant issue or specificationfollowed the guidelines for building modulesincluded the necessary unit and integration testsadded a changelog entry toCHANGELOG.md
updated the relevant documentation or specificationReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change