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

Allow user configuration of default logger to return from Ctx() #343

Merged
merged 1 commit into from Aug 12, 2021

Conversation

sean-rn
Copy link
Contributor

@sean-rn sean-rn commented Aug 11, 2021

If a user is trying to fetch a logger from their context, they probably want to log something.
A likely use case is the desire to fetch the logger from the context, but fall back to using the global logger if none is associated. This could facilitate migrating code towards using context-based loggers incrementally.

In order to keep backward compatibility with existing users of the library, we can add a configuration setting, which if left unchanged, causes the backwards compatible behavior. I chose to follow the existing pattern of configuration via global variables.

I hope that by making the configuration var a *Logger we offer maximum flexibility to users who want this feature, while keeping the existing behaviors for users who don't. Added a unit test to cover the new case.

If a user is trying to fetch a logger from their context, they probably
want to log something.  In order to allow returning a useable logger from Ctx()
without breaking backwards compatibilty with the previous behavior, we make it
configurable.
@rs rs merged commit d92a906 into rs:master Aug 12, 2021
@sean-rn sean-rn deleted the default-context-logger branch August 12, 2021 15:38
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.

None yet

2 participants