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
Is it possible for metadata to be associated with loggers out side of my application? #24
Comments
3rd party packages logs called within the request should work but with appropriate configuration. See below for For the metadata to be associated with loggers outside of the application they must fulfill some conditions. The metadata have to be accessibletmp_local vs globalThe current implementation of django-structlog/django_structlog/middlewares/request.py Lines 44 to 69 in 105acd5
It may be possible to add optional functionality in django-structlog to bind globally instead of using the tmp_local. However it has the caveat that every binds have to be unbound or they are permanent. We could implement a global binding middleware and proper documentation. ThreadsIt may have limitations if the calls are done in other threads, I never experimented with this. ConfigurationThe loggers have to be configured to use structlog. See: http://www.structlog.org/en/stable/standard-library.html I experimented that each django logger has its particularities (custom formatter, called outside of scope, etc.), I never really took the time to configure any of them completely. But I would like to add how to do it in the documentation. ConclusionYou will have to experiment yourself for now. I am really looking forward anything that would help improve this library (Pull requests (of feature or documentation), comments, etc.). I will leave this issue open until there is appropriate documentation about this or any feature that could help resolve this. |
This has been working for me to make the django-structlog context variables available to events from the stdlib logging library: In the
With inject_context_dict() defined as:
With this configuration code like
generates
|
@debfx I just tested your Do you mind if I integrate this in the library in a |
Not at all, in fact that would be great 👍 |
Fixed in 2.1.0. Thanks again @debfx. |
Is it possible for metadata to be associated with loggers out side of my application? For example, 3rd party packages or django's.
I'm seeing logs from
django.request
which don't have arequest_id
, ideally all logs associated with a single request could be associated with the samerequest_id
The text was updated successfully, but these errors were encountered: