Python Standard Library version of `structlog.BoundLogger`. Works exactly like the generic one except that it takes advantage of knowing the logging methods in advance. Use it like:: structlog.configure( wrapper_class=structlog.stdlib.BoundLogger, )
| 151 | |
| 152 | |
| 153 | class BoundLogger(BoundLoggerBase): |
| 154 | """ |
| 155 | Python Standard Library version of `structlog.BoundLogger`. |
| 156 | |
| 157 | Works exactly like the generic one except that it takes advantage of |
| 158 | knowing the logging methods in advance. |
| 159 | |
| 160 | Use it like:: |
| 161 | |
| 162 | structlog.configure( |
| 163 | wrapper_class=structlog.stdlib.BoundLogger, |
| 164 | ) |
| 165 | |
| 166 | It also contains a bunch of properties that pass-through to the wrapped |
| 167 | `logging.Logger` which should make it work as a drop-in replacement. |
| 168 | |
| 169 | .. versionadded:: 23.1.0 |
| 170 | Async variants `alog()`, `adebug()`, `ainfo()`, and so forth. |
| 171 | |
| 172 | .. versionchanged:: 24.2.0 |
| 173 | Callsite parameters are now also collected by |
| 174 | `structlog.processors.CallsiteParameterAdder` for async log methods. |
| 175 | """ |
| 176 | |
| 177 | _logger: logging.Logger |
| 178 | |
| 179 | def bind(self, **new_values: Any) -> Self: |
| 180 | """ |
| 181 | Return a new logger with *new_values* added to the existing ones. |
| 182 | """ |
| 183 | return super().bind(**new_values) |
| 184 | |
| 185 | def unbind(self, *keys: str) -> Self: |
| 186 | """ |
| 187 | Return a new logger with *keys* removed from the context. |
| 188 | |
| 189 | Raises: |
| 190 | KeyError: If the key is not part of the context. |
| 191 | """ |
| 192 | return super().unbind(*keys) |
| 193 | |
| 194 | def try_unbind(self, *keys: str) -> Self: |
| 195 | """ |
| 196 | Like :meth:`unbind`, but best effort: missing keys are ignored. |
| 197 | |
| 198 | .. versionadded:: 18.2.0 |
| 199 | """ |
| 200 | return super().try_unbind(*keys) |
| 201 | |
| 202 | def new(self, **new_values: Any) -> Self: |
| 203 | """ |
| 204 | Clear context and binds *initial_values* using `bind`. |
| 205 | |
| 206 | Only necessary with dict implementations that keep global state like |
| 207 | those wrapped by `structlog.threadlocal.wrap_dict` when threads |
| 208 | are reused. |
| 209 | """ |
| 210 | return super().new(**new_values) |
no outgoing calls
searching dependent graphs…