Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in Python Logging using dictConfig

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.

like image 795
Arun Avatar asked May 04 '11 12:05

Arun


1 Answers

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)
like image 102
Claudiu Avatar answered Oct 23 '22 16:10

Claudiu