Reputation: 6667
I'm trying to configure django to capture debug and info log messages. I have two handlers. but they only seem to want to capture warning and error messages.
Can someone help point out the silly mistake i've probably made but can't figure out.
### DJANGO LOGGING
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters':{
'hc' : {
'format': '%(asctime)s %(levelname)s %(name)s\n%(message)s'
},
},
'handlers': {
'primary_log_handler':{
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': MAIN_LOG_FILE,
# 5MB file size
'maxBytes' : 5242880,
'encoding' : 'utf-8',
'backupCount' : 5,
'formatter' : 'hc'
},
'debug_log_handler':{
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': DEBUG_LOG_FILE,
# 5MB file size
'maxBytes' : 5242880,
'encoding' : 'utf-8',
'backupCount' : 5,
'formatter' : 'hc'
},
},
'loggers': {
'some_module': {
'handlers': ['primary_log_handler', 'debug_log_handler',],}
'some_other_module': {
'handlers': ['debug_log_handler',],},
},
}
Additionally, when instantiating loggers I do:
import logging
# Get an instance of a logger
logger = logging.getLogger(__name__)
and then in the relevant code I have:
logger.debug('debug')
logger.info('info')
logger.warning('warn')
logger.error('err')
I'm on Django 1.8 and Python 2.7
Upvotes: 1
Views: 3624
Reputation: 156
It's probably late, but I got the same problem. Check the correct LOGGER_NAME in the configuration solved it:
LOGGER_NAME = 'some_module.{}'
Hope this help somebody else.
Upvotes: 0
Reputation: 1334
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {"class": "logging.StreamHandler",},
"file": {
"level": "DEBUG",
"class": "logging.FileHandler",
"filename": "log.django",
},
},
"loggers": {
"some_module": {
"handlers": ["primary_log_handler", "debug_log_handler",],
"level": "DEBUG",
},
"some_other_module": {"handlers": ["debug_log_handler",], "level": "DEBUG"},
},
}
Upvotes: 0
Reputation: 1433
Try to configure at loggers
level too:
'loggers': {
'some_module': {
'handlers': ['primary_log_handler', 'debug_log_handler',],
'level': 'DEBUG'}
'some_other_module': {
'handlers': ['debug_log_handler',],
'level': 'DEBUG'},
},
Upvotes: 3