Help me understand this logging config

Peter Otten __peter__ at web.de
Tue Aug 30 11:24:44 CEST 2011


Roy Smith wrote:

> I'm using django 1.3 and python 2.6.

Isn't dictConfig() new in 2.7? It looks like that is what you are using...

> My logging config is:
> 
> 
> LOGGING = {
>     'version': 1,
>     'disable_existing_loggers': False,
>     'formatters': {
>         'verbose': {
>             'format': '%(asctime)s: %(name)s %(levelname)s %
> (funcName)s %(message)s'
>             }
>         },
>     'handlers': {
>         'mail_admins': {
>             'level': 'ERROR',
>             'class': 'django.utils.log.AdminEmailHandler'
>         },
>         'console': {
>             'level': 'DEBUG',
>             'class': 'logging.StreamHandler',
>             'formatter': 'verbose',
> },
>     },
>     'loggers': {
>         'django.request': {'handlers': ['mail_admins'],
>                            'level': 'ERROR',
>                            'propagate': True,
>                            },
>         'djfront': {'handlers': ['console'],
>                     'propagate': True,
>                     },
> 'djfront.view': {'level': 'INFO'},
>         'djfront.auth': {'level': 'INFO'},
>         'djfront.auth.user': {'level': 'INFO'},
> 'djfront.api': {'level': 'WARN'},
>         }
>     }
> 
> In my code, I do:
> 
> logger = logging.getLogger('djfront.auth.facebook')
> 
> Since I haven't configured a 'djfront.auth.facebook' logger, it should
> inherit the 'djfront.auth' config, which means the logging level
> should be set to INFO.  But, when I do:
> 
>     logger.debug('redirecting to "%s"' % url)
> 
> it emits a message:
> 
> 2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init
> redirecting to [...]
> 
> I'm confused.  Why is the debug level message not getting filtered
> out?

I tried your setup with the django-specific handler replaced by another 
StreamHandler

$ cat tmp_logging.py
import logging
import logging.config

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s: %(name)s %(levelname)s %(funcName)s 
%(message)s'
            }
        },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'logging.StreamHandler' 
#'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'django.request': {'handlers': ['mail_admins'],
                           'level': 'ERROR',
                           'propagate': True,
                           },
        'djfront': {'handlers': ['console'],
                    'propagate': True,
                    },
        'djfront.view': {'level': 'INFO'},
        'djfront.auth': {'level': 'INFO'},
        'djfront.auth.user': {'level': 'INFO'},
        'djfront.api': {'level': 'WARN'},
        }
    }

logging.config.dictConfig(LOGGING)

logger = logging.getLogger('djfront.auth.facebook')
logger.info("info-test")
logger.debug("debug-test")

and got what

$ python2.7 tmp_logging.py
2011-08-30 11:18:33,160: djfront.auth.facebook INFO <module> info-test
$

which seems to be what you expected. So I'm confused, too...




More information about the Python-list mailing list