python - Django log messages not processing correctly. Messages to multiple files -
so have 2 loggers in django project. 1 authentication failures, , 1 includes includes messages when edited (basically have logger command). seem have bit of problem in modules want use both loggers however. 2 loggers defined so:
'': { 'handlers': ['file'], 'level': 'info', 'propagate': true, }, 'auth': { 'handlers': ['file_auth'], 'level': 'critical', 'propagate': true, }
and handlers are:
'file': { 'level': 'info', 'class': 'logging.filehandler', 'filename': '/home/debug.log', 'formatter': 'simple', }, 'file_auth': { 'level': 'critical', 'class': 'logging.filehandler', 'filename': '/home/debug2.log', 'formatter': 'verbose', },
at top of django view, have
import logging logger = logging.getlogger('') logger = logging.getlogger('auth')
then within 1 view have logger.info(message). if change logger.critical(message), message appears in both log files if remains logger.info, nothing happens @ all.
(probably useless information...at start of logging section in settings.py, have:
'version': 1, 'disable_existing_loggers': false,
not sure if have relevance. struggling errors appear in both files until switched order of introducing them magically changed stuff - don't understand why make difference though)
would grateful if me out....probably simple must admit don't understand how works..
you have 2 different loggers, named ''
(the root logger) , 'auth'
. order in 2 statements appear:
logger = logging.getlogger('') logger = logging.getlogger('auth')
obviously makes difference when call
logger.info(...)
as in 2 cases calling method on 2 different loggers. might wish change code to
root_logger = logging.getlogger('') logger = logging.getlogger('auth')
and call methods on either root_logger
or logger
appropriate.
Comments
Post a Comment