NOTE I'm aware of this answer but that doesn't work for me, I am hoping for a complete, self-contained working example.
I'm trying to replace logging.basicConfig
with dictConfig
in Python (2.7)
My understanding is basicConfig
simply sets up the root logger: so I'm attempting to do the same with the dictConfig
. That is, set up the root logger with a handler, and then all the loggers in my application will propagate up the root logger.
What's missing from the following snippet? The behaviour is the log file is created, but no output makes it. (I've tried various combos of setting levels, it doesn't appear to help)
import logging
log_dict = {
'loggers': {
'root': {
'handlers': ['file_handler']
}
},
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file_handler': {
'filename': 'c:/mylogfile.log',
'class': 'logging.FileHandler'
}
}
}
logging.config.dictConfig(log_dict)
logging.info('THIS IS A TEST')
logging.shutdown()
exit()