I'm trying to set up logging in my Django 2.1 app, but I can't get INFO logs to display. ERROR and WARNING show, but never INFO.
I added a custom LOGGING set in my settings.py, but it doesn't seem to affect the actual logging. I've tried changing the levels, changing the formatters, turning on disable_existing_loggers. I'm pretty certain that Django just ignores LOGGING, but https://docs.djangoproject.com/en/2.1/topics/logging/#configuring-logging and everywhere I look seems to indicate otherwise.
What do do?!
DETAILS:
I'm running this in Heroku with gunicorn, but also run via python manage.py runserver
and it acts the same.
In my ./api/v1/serializers.py and ./users/models.py I've added logging like this:
import logging
logger = logging.getLogger(__name__)
...
...
...
logger.info('Test log INFO')
logger.warning('Test log WARNING')
logger.error('Test log ERROR')
My settings are at ./amp/settings.py and have this:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d: %(message)s',
},
'simple': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'INFO',
'formatter': 'verbose',
'filters': [],
},
'file': {
'class': 'logging.FileHandler',
'level': 'DEBUG',
'filename': '/tmp/amp-server/debug.log',
'formatter': 'verbose',
},
},
'loggers': {
'': {
'level': 'INFO',
'propagate': True,
'handlers': ['console', 'file'],
'filters': [],
},
'django.request': {
'level': 'DEBUG',
'propagate': False,
'handlers': ['console'],
},
},
}
There's nowhere else that references settings.py's LOGGING. I've tried adding explicit loggers named after my project and apps (amp, amp.api, api, etc) to no avail like:
'amp': {
'level': 'INFO',
'propagate': True,
'handlers': ['console', 'file'],
'filters': [],
},
And later logger = logging.getLogger('amp')
, but that doesn't make a difference. I'm fairly certain Django ignores my settings.py LOGGING or overwrites it. (Before you ask, LOGGING is not referenced anywhere else in my codebase but settings.py.)
I've carefully combed through the Django LOGGING and Python dictConfig docs, copy-pasted-and-tweaked LOGGING settings from blogs and StackOverflow posts but nothing helps!
NOTE: This is not a duplicate of Why Django logging skips log entries? - those answers are trying to fix a broken LOGGING value, rather than dealing with the fact that LOGGING isn't being used at all. logging.basicConfig can change the logging settings, but the general LOGGING config is still ignored in my settings.py.