Invalid scrapy setting logging?

in pipelines, the code is as follows:

import logging
from scrapy.utils.log import configure_logging

configure_logging(install_root_handler=False)
logging.basicConfig(
    filename="log.txt",
    format="%(levelname)s: %(message)s",
    level=logging.INFO
)  
logging.error("s")

will output on the console SRAV 2018-11-12 19:19:53 [root] ERROR: s
will not be output to the set log.txt.
Why?

Mar.26,2022

has encountered a similar problem, which I haven't solved completely, which may be due to the global setting problem of logging. Because logging is in singleton mode, and basicConfig will not work if root logging is already set up. In large projects, you should make global settings for logging before reading all modules, otherwise conflicts may occur.


if it has been set in other modules, it cannot be set again. I also encountered it today when I found that there was basicConfig in one of my modules, causing the subsequent settings to be invalid.

Menu