python logging module is not writing anything to file

python logging module is not writing anything to file

Try calling

logger.error(This should go to both console and file)

instead of

logging.error(this will go to the default logger which you have not changed the config of)

Try to put the import and the basicConfig at the very beggining of the script. Something like this:

import logging
logging.basicConfig(filename=log.log, level=logging.INFO)
.
.
import ...
import ...

python logging module is not writing anything to file

Put this

for handler in logging.root.handlers[:]:
    logging.root.removeHandler(handler)

in front of the

logging.basicConfig(...)

see also
Logging module not writing to file

Leave a Reply

Your email address will not be published.