What is wrong with this code? It prints out Whatsup to the stdOut, and nothing to the file in /tmp. It creates the file, but nothing is ever written to it, not even when loggging loads of data ('w'*20000). And there doesn't seem to be any handler specified either after I check.
>>> logger.handlers
[]
>>> logger.warning("Whatsup")
Whatsup
>>>
import logging
import logging.config
import multiprocessing
import threadfilter
VERBOSE_LOGGING = 1
directory = '/tmp/'
configDict = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'detailed': {
'class': 'logging.Formatter',
'format': '%(asctime)s - %(levelname)s =%(threadName)s= - Completer: %(message)s'
}
},
'handlers': {
'fileH': {
'class': 'logging.FileHandler',
'filename': '%s/ZZZZZZZZZZ_dispatcher_jobComplete3r.log' % (directory),
'formatter': 'detailed'
}
},
'loggers': {
'root': {
'handlers': ['fileH'],
'level': VERBOSE_LOGGING
}
}
}
logging.config.dictConfig(configDict)
logger = logging.getLogger()
logger.handlers
logger.warning("Whatsup")
No errors are thrown either, it just seems to silently ignore my config.
Python 3.6.1
Posted 2 second too soon.
I had to explicitely call the name of the root logger in my getLogger call. This did the trick:
logging.config.dictConfig(configDict)
logger = logging.getLogger('root')
logger.handlers
logger.warning("Whatsup")
Sorry!