-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: log: modify Logger
struct, make it supports multi output
#33454
Comments
The change you've proposed isn't at all backwards compatible and it's also unnecessary. You can achieve exactly this using |
I may have found out what caused incompatibility, and I'll fix it. |
This is still a backwards-incompatible change; SetOutput used to replace the writer, while in your CL above it appends. I agree with @tmthrgd that you should simply use an io.MultiWriter here. Having one way to achieve something with less API is simpler than having many ways to do the same. |
As others have said, this is a backwards incompatible change, which makes it not something we can accept. Most people who use I/O in Go for a while end up finding io.MultiWriter to be direct, simple, and natural. I would suggest using it and finding out. Note that you can build up the "add a new output to an existing logger" pattern for yourself by using
If that's something you do all the time, you could put it in your own library. Closing because it is a backwards-incompatible change with an easy implementation outside the standard library. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No, but this part of the source code is no different from the latest version.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I Modified the field
out
of the structureLogger
in packagelog
, reset it toouts
, which type is[]io.Writer
, and the relevant places involving the operation outs.The goal is to support multiple outputs of log information, such as simultaneous output to files and consoles, and more.
These changes do not affect the code execution of other completed projects that call the
log
packagePR_FilesChanged
: #33450What did you expect to see?
I want to set the output of log information to multiple
oi.Writer
at the same time through the built-in function oflog
package onveniently and quickly. Because in large projects nowadays, it is usually necessary to save logs in many format to many places, to do some data analysis of service operation by the log informations, etc.What did you see instead?
At present, the only way to output log information to multiple places at the same time is to create multiple
logger
and then process the same log information by eachlogger
.The text was updated successfully, but these errors were encountered: