Helper that takes the dictionary output from the methods in LogFormatter and adapts it into a tuple of positional arguments for logger.log calls, handling backward compatibility as well.
(
logkws: LogFormatterResult,
)
| 243 | |
| 244 | |
| 245 | def logformatter_adapter( |
| 246 | logkws: LogFormatterResult, |
| 247 | ) -> tuple[int, str, dict[str, Any] | tuple[Any, ...]]: |
| 248 | """ |
| 249 | Helper that takes the dictionary output from the methods in LogFormatter |
| 250 | and adapts it into a tuple of positional arguments for logger.log calls, |
| 251 | handling backward compatibility as well. |
| 252 | """ |
| 253 | |
| 254 | level = logkws.get("level", logging.INFO) |
| 255 | message = logkws.get("msg") or "" |
| 256 | # NOTE: This also handles 'args' being an empty dict, that case doesn't |
| 257 | # play well in logger.log calls |
| 258 | args = cast("dict[str, Any]", logkws) if not logkws.get("args") else logkws["args"] |
| 259 | |
| 260 | return (level, message, args) |
| 261 | |
| 262 | |
| 263 | # LoggerAdapter is only parameterized since Python 3.11 |
no test coverage detected