Python logging default dictconfig sample

Published 1 month ago about python, snippets, ...

Sample dictConfig for python logging module

logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'standard',
        },
        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': '/tmp/stash-notifier.log',
            'formatter': 'standard',
            'maxBytes': 1024*1024*10,
            'backupCount': 5,
        },
    },
    'root': {
        'level': 'DEBUG',
        'handlers': ['console', ]
    },
})