Below is the configuration dict i am using:
LOGGING_CONF = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handler': {
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': 'D:\workspace\yogasync\codes\code_svn\YogaSync\log\workspacelogconfig.log',
'maxBytes': 20480,
'backupCount': 3,
},
},
'logger': {
'extensive': {
'level':'DEBUG',
'handlers': 'file'
},
},
}
in a module where i need to create logs i have inserted the below code:
import logging
import logging.config
logging.config.dictConfig(LOGGING_CONF)
logger = logging.getLogger('extensive')
logger.info("This is my first log")
When i execute this, no errors are raised, however no logs get created. I am not sure what is missing out. I want to use dictCongif only Please help me with this.
You have to add a handler so that something happens with all those loggers. For example,
logfile = logging.handlers.FileHandler("mylog.log")
logfile.setLevel(logging.DEBUG)
logfile.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(module)s: %(message)s'))
logging.getLogger('').addHandler(logfile)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With