MCPcopy
hub / github.com/scrapy/scrapy / configure_logging

Function configure_logging

scrapy/utils/log.py:91–134  ·  view source on GitHub ↗

Initialize logging defaults for Scrapy. :param settings: settings used to create and configure a handler for the root logger (default: None). :type settings: dict, :class:`~scrapy.settings.Settings` object or ``None`` :param install_root_handler: whether to install root lo

(
    settings: Settings | dict[_SettingsKey, Any] | None = None,
    install_root_handler: bool = True,
)

Source from the content-addressed store, hash-verified

89
90
91def configure_logging(
92 settings: Settings | dict[_SettingsKey, Any] | None = None,
93 install_root_handler: bool = True,
94) -> None:
95 """
96 Initialize logging defaults for Scrapy.
97
98 :param settings: settings used to create and configure a handler for the
99 root logger (default: None).
100 :type settings: dict, :class:`~scrapy.settings.Settings` object or ``None``
101
102 :param install_root_handler: whether to install root logging handler
103 (default: True)
104 :type install_root_handler: bool
105
106 This function does:
107
108 - Route warnings and twisted logging through Python standard logging
109 - Assign DEBUG and ERROR level to Scrapy and Twisted loggers respectively
110 - Route stdout to log if LOG_STDOUT setting is True
111
112 When ``install_root_handler`` is True (default), this function also
113 creates a handler for the root logger according to given settings
114 (see :ref:`topics-logging-settings`). You can override default options
115 using ``settings`` argument. When ``settings`` is empty or None, defaults
116 are used.
117 """
118 if not sys.warnoptions:
119 # Route warnings through python logging
120 logging.captureWarnings(True)
121
122 observer = twisted_log.PythonLoggingObserver("twisted")
123 observer.start()
124
125 dictConfig(DEFAULT_LOGGING)
126
127 if isinstance(settings, dict) or settings is None:
128 settings = Settings(settings)
129
130 if settings.getbool("LOG_STDOUT"):
131 sys.stdout = StreamLogger(logging.getLogger("stdout"))
132
133 if install_root_handler:
134 install_scrapy_root_handler(settings)
135
136
137_scrapy_root_handler: logging.Handler | None = None

Callers 15

__init__Method · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 5

SettingsClass · 0.90
StreamLoggerClass · 0.85
startMethod · 0.45
getboolMethod · 0.45