MCPcopy
hub / github.com/scrapy/scrapy / logformatter_adapter

Function logformatter_adapter

scrapy/utils/log.py:245–260  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

243
244
245def 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

Callers 4

_scrapeMethod · 0.90
handle_spider_errorMethod · 0.90
start_itemproc_asyncMethod · 0.90
_downloadMethod · 0.90

Calls 1

getMethod · 0.45

Tested by

no test coverage detected