I am not sure why django is not logging anything less than "WARNING" level. I have this code in the view:
logger = logging.getLogger(__name__)
def profile_data(request):
logging.info("INFO PROFILE DATA!!")
logging.debug("DEBUG PROFILE DATA!!")
logging.warning("WARNING PROFILE DATA!!")
logging.error("ERROR PROFILE DATA!!")
and this in my settings.py:
# Logging
LOGGING = {
'version': 1,
# Version of logging
'disable_existing_loggers': False,
'filters': {
# information regarding filters
},
'formatters': {
'<simple_format>': {
'format': '{levelname} {message}',
'style': '{',
}
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/logs/log_file1.log',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler'
},
},
'loggers': {
'django': {
'handlers': ['file', 'console'],
'level': 'DEBUG',
},
'root': {
'handlers': ['file', 'console'],
'level': 'DEBUG',
}
}
}
As you can see, I try to set everything to the DEBUG level, it doesn't work, I only see this is the warning and error level in the terminal:
WARNING:root:WARNING PROFILE DATA!!
ERROR:root:ERROR PROFILE DATA!!
EDIT
changed the logger declaration to:
logger = logging.getLogger('app_logger')
the call to:
logger.info("INFO PROFILE DATA!!")
and the settings to the new name, of course:
'loggers': {
'app_logger': {
'handlers': ['file', 'console'],
'level': 'DEBUG',
},
But it still prints only WARNING and above. When am I declaring a new logger? shouldn't logging.getLogger()
get the logger declared in the settings? how should I import that logger in my views?
Also, tried adding the logger to the top level of the dict key as suggested by an answer below ('app_logger': {"level": "DEBUG", "handler": "console"},
) it didn't work.