-
Notifications
You must be signed in to change notification settings - Fork 403
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
Feature request: Implement a context manager to bind variables to a logger #2062
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
hey @wesleyhamburger-okta thanks for raising this feature request. Please allow me to ask some questions to make sure I understand it correctly:
Reason I ask that is stateDiagram
[*] --> Logger
Logger --> new_logger
new_logger --> append(user_id)
append(user_id) --> perform_operation()
perform_operation() --> remove(user_id)
new_logger --> [*]
We, on the other hand, would append stateDiagram
[*] --> Logger
Logger --> append(user_id)
append(user_id) --> perform_operation()
perform_operation() --> remove(user_id)
remove(user_id) --> [*]
[*] --> LoggerElsewhere
LoggerElsewhere --> bi_directional_state
LoggerElsewhere --> receives_user_id_too
receives_user_id_too --> user_id_removed
user_id_removed --> [*]
The former would need a better name to not confuse existing Looking forward to hearing from you. PS: If it's primarily boilerplate, we'd welcome a contribution and can guide/co-develop you all the way through to expedite this for the next release :) Thanks a lot!!
Example for question 2 with logger.bind(user_id="123") as new_logger:
# new_logger.info() would have `user_id` key... but if I do logger.info()... `user_id` would not be present
# similarly, perform_operation() OR any other function with a `logger` instance wouldn't have `user_id`
perform_operation() |
Related #3719 |
Use case
I wan't to add variables to the logger for the duration of a request and get clean up for free without needing to explicitly call delete.
This is similar to https://www.structlog.org/en/stable/api.html#structlog.contextvars.bound_contextvars
Solution/User Experience
Alternative solutions
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: