开发者

Issue in Python Logging using dictConfig

Below is the configuration dict i am using:

LOGGING_CONF = {
'version': 1,
'disable_existing_loggers': False,
'formatters': { 
开发者_如何学C    '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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜