-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(logger): add logger option to all micro components (override DefaultLogger) closes #2556 #2559
feat(logger): add logger option to all micro components (override DefaultLogger) closes #2556 #2559
Conversation
eac039c
to
d116596
Compare
@asynxc Really nice PR, thanks! Two thoughts; In the log helper, you implemented the checks to see if a level is enabled, I know this was present in the original code, but this should be the responsibility of the logger implementation (plugin), so I think we can remove those checks. Also, if I set the logger for the service globally, I also expect it to be set for all sub-modules/plugins unless specifically specified otherwise. I don't think this is currently implemented right? |
I agree with you, the original code does unnecessarily a double log level check (in the logger and in inline) the default logger default and plugins logger does check log level, so i guess i can ditch using the Helper. i have added a commit to do that, please take a look. @Davincible
no it's not the case at the moment, maybe can be done in a second iteration ^^ |
About the setup of the logger; the problem is that components can be initialized at different stages, which makes it difficult to reliably pass down the logger to all components, unfortunately. The downside of this is that you might need to define it multiple times. I'm afraid that passing in a logger will raise the expectation that it will be used everywhere, where this will only be used in the service. micro.NewService(
micro.WithLogger(logger)
) |
I agree with you, it's a valid assumption. @Davincible thoughts ? |
The problem with just setting the global logger in the option is that there is no guarantee of order. The option can be executed before or after defaults are initialized. The only solution I see, is to make the logger in all services pointers, and by default point to the global variable, which we can then change at any point in time in the setup phase. If a user passes in a custom logger, then the logger wont be pointing to the global anymore |
Turns out that's not how it works. I've been trying to implement it but can't come up with any consistent way. So for now the user will still have to manually set the |
@asynxc this is ready to be merged now. Have you been able to work on the plugins PR? |
that's great ! I'm waiting for this PR to land and a go-micro release to be able to reuse the interfaces in plugins |
@asynxc released! |
@asynxc Any progress? |
closes #2556
(to get a better understanding of the reason bedind this PR, please checkout this issue #2556
A PR to allow providing a custom logger to every micro component (client, server, store, broker,...).
the guide lines of this implementation are :
Any feedback is welcome ^^