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 foreign_pre_chain To Read Foreign Log Args #228

Merged

Conversation

@jonathanmeier5
Copy link
Contributor

jonathanmeier5 commented Sep 26, 2019

Resolves #227

When migrating a project from stdlib logging to structlog, an easy first step is to use ProcessorFormatter with processors defined in foreign_pre_chain. These will run on every stdlib log message sent into the formatter.

However, right now there is no way to access a LogRecord's args in the foreign_pre_chain processors because they are stripped before the record is passed to the processors.

This PR introduces a pass_foreign_args kwarg to ProcessorFormatter. When set to True, it will inject a foreign log record's args attribute into the event_dict under the positional_args key before stripping them from the record.

@hynek hynek merged commit 5a3599e into hynek:master Oct 15, 2019
22 checks passed
22 checks passed
codecov/patch 100% of diff hit (target 100%)
Details
codecov/project 100% (target 100%)
Details
hynek.structlog Build #20190926.1 succeeded
Details
hynek.structlog (Test Docs) Test Docs succeeded
Details
hynek.structlog (Test Lint) Test Lint succeeded
Details
hynek.structlog (Test Manifest) Test Manifest succeeded
Details
hynek.structlog (Test PyPI-Description) Test PyPI-Description succeeded
Details
hynek.structlog (Test py27-colorama) Test py27-colorama succeeded
Details
hynek.structlog (Test py27-greenlets) Test py27-greenlets succeeded
Details
hynek.structlog (Test py27-oldtwisted) Test py27-oldtwisted succeeded
Details
hynek.structlog (Test py27-threads) Test py27-threads succeeded
Details
hynek.structlog (Test py35-threads) Test py35-threads succeeded
Details
hynek.structlog (Test py36-threads) Test py36-threads succeeded
Details
hynek.structlog (Test py37-colorama) Test py37-colorama succeeded
Details
hynek.structlog (Test py37-greenlets) Test py37-greenlets succeeded
Details
hynek.structlog (Test py37-oldtwisted) Test py37-oldtwisted succeeded
Details
hynek.structlog (Test py37-threads) Test py37-threads succeeded
Details
hynek.structlog (Test pypy-colorama) Test pypy-colorama succeeded
Details
hynek.structlog (Test pypy-greenlets) Test pypy-greenlets succeeded
Details
hynek.structlog (Test pypy-oldtwisted) Test pypy-oldtwisted succeeded
Details
hynek.structlog (Test pypy-threads) Test pypy-threads succeeded
Details
hynek.structlog (Test pypy3-threads) Test pypy3-threads succeeded
Details
@hynek

This comment has been minimized.

Copy link
Owner

hynek commented Oct 15, 2019

Thanks! There's a bunch of very minor things but now that 3.8 has been dropped on me I need to publish fast so I'll shape it up myself.

hynek added a commit that referenced this pull request Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.