I am logging messages from various modules and want to change the log level dynamically. The code snippet is
import logging
logging.basicConfig(filename='my_log.log', filemode='w', encoding='utf-8', level=logging.WARNING, force=True)
# Code here that works so only worry about WARNINGs
# ....
# Code here has an issue so increase log level to DEBUG
logging.setLevel(logging.DEBUG)
This gives the error AttributeError: module 'logging' has no attribute 'setLevel'. I tried using the logger generated by basicConfig, e.g.
L = logging.basicConfig(filename='my_log.log', filemode='w', encoding='utf-8', level=logging.INFO, force=True)
L.setLevel(logging.DEBUG)
but got the error AttributeError: 'NoneType' object has no attribute 'logging'. How can I do this?
AttributeError: 'NoneType' object has no attribute 'setLevel'in the last example?