1 | initial version |
The 'basicConfig' for logging can be modified even after it is already established by using the following steps:
import logging
logger = logging.getLogger()
logger.setLevel()
and logger.addHandler()
. For example:logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger
instance.Note: It is recommended to modify the basicConfig as early as possible in the application's code to ensure all logging statements are made using the desired configuration.