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

Moved the capture location for structlog to first in the processor chain #118

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/integrations/structlog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ Using with :mod:`structlog`
do_something()
logot.assert_logged(logged.info("App started"))

:mod:`logot` preserves the preconfigured :mod:`structlog` processor chain. Events are captured at the end of the chain,
but before the final processor, as it is responsible for emitting the log event to the underlying logging system. For
more information, see the
`structlog documentation <https://www.structlog.org/en/stable/processors.html#adapting-and-rendering>`_.
:mod:`logot` will capture logs before any processors are invoked. Any filtering, formatting, or other processing from
the processor chain will not be applied to the captured logs.

.. note::

Expand Down
8 changes: 1 addition & 7 deletions logot/_structlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ def start_capturing(self, logot: Logot, /, *, level: Level, name: Name) -> None:
else:
levelno = level

# We need to insert our processor before the last processor, as this is the processor that transforms the
# `event_dict` into the final log message. As this depends on the wrapped logger's formatting requirements,
# it can interfere with our capturing.
# See https://www.structlog.org/en/stable/processors.html#adapting-and-rendering
structlog.configure(
processors=[*processors[:-1], partial(_processor, logot=logot, name=name, levelno=levelno), processors[-1]]
)
structlog.configure(processors=[partial(_processor, logot=logot, name=name, levelno=levelno), *processors])

def stop_capturing(self) -> None:
structlog.configure(processors=self._old_processors)
Expand Down