-
Notifications
You must be signed in to change notification settings - Fork 259
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
Add an optional logger param #664
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
155a28d
to
2851f2b
Compare
Signed-off-by: tison <[email protected]>
tests/integration.rs
Outdated
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.
This is just a good target to test our new logger
param.
Previously, the global logger state is shared with all the macros
tests and causes the result unstable.
Signed-off-by: tison <[email protected]>
I'm not convinced this is a common enough use case that it has to be in facade, couldn't it be implemented in the logging implementation? |
spdlog-rs implements this, with their own So, the logging implementation must implement the same functionality by bypassing our macro, which loses the value of a facade. If you have an idea how to implement and use it with our abstraction and a custom impl crate, I'm glad to know. |
I my crate I used the |
Thanks for your information! I'm considering the difference between target and a logger field also. In the description:
Switching targets still use the same (global & singleton) logger instance, while setting a new logger instance can avoid meta logging cycle - #645. |
The global logging implementation can be set up to call different loggers depending on |
Personally, I think being able to target a different logger entirely using an argument is useful in a few scenarios:
From a maintenance perspective it also keeps us a bit honest in not being able to assume that everything is shared by a single global logger. If @Thomasdezeeuw isn't convinced it's worth adding though then we'll leave it for the time being. |
I'm not convinced the additional complexity is worth the use case that is already possible via the log implementation. @tisonkun do you have any argument why it should be done this way, and not via the log implementation? |
It's included in the issue description of #645:
That said, passing a logger instance is determinate for what is installed in the log implementation (pipeline), while target is a loose contract (convention). If you have a single log instance with a Kafka appender installed, you may first filter out logs with target "kafka". But what if a user application uses the same target for their actions over kafka? Then you need to agree on a reserved target and every user should learn about it. Instead, a pass-in logger can be an explicit contract that the certain logger is used by kafka client internally (if a client library adopts this) and thus you can fine tune the manner and be sure that it would be used in that scenario.
This is also a good point that when you have different log requirements for different components, instead of making a global instance and dispatching the application logic (rather than barely appending to multiple destinations), it would be easier to keep the logger instance separated. Finally, if we support logging with a pass-in instance, it's possible to use a global instance everywhere. But the reverse direction is not true. slog's macros always has a logger param, while there is slog-global to use a global instance when it's satisfied. |
This closes #645
@KodrAus I noticed that we previously introduced
target
for similar usage, but switching to a different logger is different.This patch is for preview. I'm not quite sure how we pass the customized logger. The current implementation seems good. I think the
log
crate itself isn't suitable to hold a globalname -> logger
registry: that would be too heavy and too specific.