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

feat(logger): add logger option to all micro components (override DefaultLogger) closes #2556 #2559

Merged
merged 11 commits into from
Sep 29, 2022

Conversation

asynxc
Copy link
Contributor

@asynxc asynxc commented Sep 24, 2022

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 :

  • do not change components API (for retro compatibility)
  • add Logger option to every component
  • fallback to DefaultLogger if no logger option provided (for retro compatibility)

Any feedback is welcome ^^

@asynxc asynxc force-pushed the feat/logger/add_logger_option branch from eac039c to d116596 Compare September 24, 2022 14:52
@Davincible
Copy link
Contributor

Davincible commented Sep 24, 2022

@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?

@asynxc
Copy link
Contributor Author

asynxc commented Sep 26, 2022

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.

I agree with you, the original code does unnecessarily a double log level check (in the logger and in inline)
Also the logger.Helper does the log level check, but i dit not want to change its behavior/api since it's a public API...

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

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?

no it's not the case at the moment, maybe can be done in a second iteration ^^
Edit: Service has no direct access to most components, so in order to pass in the service Logger, components must forward it in to "child" components, and must be careful doing that to not override already setup"child" option logger... so for those reasons i don't think auto setup logger for all components using Service logger is good idea...
The user can always customize Service/global level logger by changing the DefaultLogger
@Davincible thoughts ?

@Davincible
Copy link
Contributor

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)
)

@asynxc
Copy link
Contributor Author

asynxc commented Sep 26, 2022

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.

I agree with you, it's a valid assumption.
to accommodate this we can auto set DefaultLogger by the service logger set by the user via micro.WithLogger ?
this way the service logger will used everywhere...

@Davincible thoughts ?

@Davincible
Copy link
Contributor

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

@Davincible
Copy link
Contributor

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 DefaultLogger, at least you can now manually specify the loggers for the different interfaces

service.go Outdated Show resolved Hide resolved
@Davincible
Copy link
Contributor

@asynxc this is ready to be merged now. Have you been able to work on the plugins PR?

@asynxc
Copy link
Contributor Author

asynxc commented Sep 29, 2022

@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

@Davincible Davincible merged commit 1db3635 into micro:master Sep 29, 2022
@Davincible
Copy link
Contributor

@asynxc released!

@Davincible
Copy link
Contributor

I'm waiting for this PR to land and a go-micro release to be able to reuse the interfaces in plugins

@asynxc Any progress?

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.

[FEATURE] allow passing custom logger to "server" component
2 participants