-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
public access to logger._context #266
Comments
I've already promised someone somewhere to keep |
+1 for a public method to get the bound context. We use |
Also: should we return the actual context or a copy? 🤔 |
I have added it in 33008b0, pls yell if something is missing. |
Thanks @hynek, sorry I was not around to respond to your comment. This looks perfect. |
Am I bad for wanting to access
logger._context
?Here's my use case: exception logging with extra context from inner frames in the stack.
I don't want to log directly in my exception handler because there's already code higher up the stack which does its own logging:
Then, I could write a processor that looks for
_structlog_context
on logged exceptions and return that additional context.Really, all this exception-handling stuff is kinda orthogonal to request I have, but it shows my motivation. This "extra context on exception" feature could be implemented without being able to access an existing log's context; however, it naturally leads me to want to attach my logger's context to these exceptions, since those loggers are already convenient containers for all the context I want to attach.
So, I'm already doing this in production, but I'm having to access the private
_context
attribute. Is there some other way to get the context that I missed? Can we have aget_context()
method?The text was updated successfully, but these errors were encountered: