MCPcopy Create free account
hub / github.com/hynek/structlog / ProcessorFormatter

Class ProcessorFormatter

src/structlog/stdlib.py:1010–1249  ·  view source on GitHub ↗

r""" Call *structlog* processors on `logging.LogRecord`\s. This is an implementation of a `logging.Formatter` that can be used to format log entries from both *structlog* and `logging`. Its static method `wrap_for_formatter` must be the final processor in *structlog*'s processo

Source from the content-addressed store, hash-verified

1008
1009
1010class ProcessorFormatter(logging.Formatter):
1011 r"""
1012 Call *structlog* processors on `logging.LogRecord`\s.
1013
1014 This is an implementation of a `logging.Formatter` that can be used to
1015 format log entries from both *structlog* and `logging`.
1016
1017 Its static method `wrap_for_formatter` must be the final processor in
1018 *structlog*'s processor chain.
1019
1020 Please refer to :ref:`processor-formatter` for examples.
1021
1022 Args:
1023 foreign_pre_chain:
1024 If not `None`, it is used as a processor chain that is applied to
1025 **non**-*structlog* log entries before the event dictionary is
1026 passed to *processors*. (default: `None`)
1027
1028 processors:
1029 A chain of *structlog* processors that is used to process **all**
1030 log entries. The last one must render to a `str` which then gets
1031 passed on to `logging` for output.
1032
1033 Compared to *structlog*'s regular processor chains, there's a few
1034 differences:
1035
1036 - The event dictionary contains two additional keys:
1037
1038 #. ``_record``: a `logging.LogRecord` that either was created
1039 using `logging` APIs, **or** is a wrapped *structlog* log
1040 entry created by `wrap_for_formatter`.
1041
1042 #. ``_from_structlog``: a `bool` that indicates whether or not
1043 ``_record`` was created by a *structlog* logger.
1044
1045 Since you most likely don't want ``_record`` and
1046 ``_from_structlog`` in your log files, we've added the static
1047 method `remove_processors_meta` to ``ProcessorFormatter`` that
1048 you can add just before your renderer.
1049
1050 - Since this is a `logging` *formatter*, raising
1051 `structlog.DropEvent` will crash your application.
1052
1053 keep_exc_info:
1054 ``exc_info`` on `logging.LogRecord`\ s is added to the
1055 ``event_dict`` and removed afterwards. Set this to ``True`` to keep
1056 it on the `logging.LogRecord`. (default: False)
1057
1058 keep_stack_info:
1059 Same as *keep_exc_info* except for ``stack_info``. (default: False)
1060
1061 logger:
1062 Logger which we want to push through the *structlog* processor
1063 chain. This parameter is necessary for some of the processors like
1064 `filter_by_level`. (default: None)
1065
1066 pass_foreign_args:
1067 If True, pass a foreign log record's ``args`` attribute to the

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…