Combines creates an ``event_dict`` and runs the chain. Call it to combine your *event* and *context* into an event_dict and process using the processor chain. Args: method_name: The name of the logger method. Is passed into the processo
(
self, method_name: str, event: str | None, event_kw: dict[str, Any]
)
| 121 | # Helper methods for sub-classing concrete BoundLoggers. |
| 122 | |
| 123 | def _process_event( |
| 124 | self, method_name: str, event: str | None, event_kw: dict[str, Any] |
| 125 | ) -> tuple[Sequence[Any], Mapping[str, Any]]: |
| 126 | """ |
| 127 | Combines creates an ``event_dict`` and runs the chain. |
| 128 | |
| 129 | Call it to combine your *event* and *context* into an event_dict and |
| 130 | process using the processor chain. |
| 131 | |
| 132 | Args: |
| 133 | method_name: |
| 134 | The name of the logger method. Is passed into the processors. |
| 135 | |
| 136 | event: |
| 137 | The event -- usually the first positional argument to a logger. |
| 138 | |
| 139 | event_kw: |
| 140 | Additional event keywords. For example if someone calls |
| 141 | ``log.info("foo", bar=42)``, *event* would to be ``"foo"`` and |
| 142 | *event_kw* ``{"bar": 42}``. |
| 143 | |
| 144 | Raises: |
| 145 | structlog.DropEvent: if log entry should be dropped. |
| 146 | |
| 147 | ValueError: |
| 148 | if the final processor doesn't return a str, bytes, bytearray, |
| 149 | tuple, or a dict. |
| 150 | |
| 151 | Returns: |
| 152 | `tuple` of ``(*args, **kw)`` |
| 153 | |
| 154 | .. note:: |
| 155 | Despite underscore available to custom wrapper classes. |
| 156 | |
| 157 | See also `custom-wrappers`. |
| 158 | |
| 159 | .. versionchanged:: 14.0.0 |
| 160 | Allow final processor to return a `dict`. |
| 161 | .. versionchanged:: 20.2.0 |
| 162 | Allow final processor to return `bytes`. |
| 163 | .. versionchanged:: 21.2.0 |
| 164 | Allow final processor to return a `bytearray`. |
| 165 | """ |
| 166 | # We're typing it as Any, because processors can return more than an |
| 167 | # EventDict. |
| 168 | event_dict: Any = self._context.copy() |
| 169 | event_dict.update(**event_kw) |
| 170 | |
| 171 | if event is not None: |
| 172 | event_dict["event"] = event |
| 173 | for proc in self._processors: |
| 174 | event_dict = proc(self._logger, method_name, event_dict) |
| 175 | |
| 176 | if isinstance(event_dict, (str, bytes, bytearray)): |
| 177 | return (event_dict,), {} |
| 178 | |
| 179 | if isinstance(event_dict, tuple): |
| 180 | # In this case we assume that the last processor returned a tuple |