settings.py is just Python, so we can do:
from django.utils.log import DEFAULT_LOGGING # Use defaults as the basis for our logging setup LOGGING = DEFAULT_LOGGING # We need some formatters. These ones are from the docs. LOGGING['formatters'] = { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' }, 'simple': { 'format': '%(levelname)s %(message)s' }, } # A log file handler that rotates periodically LOGGING['handlers'].update({ 'rotate': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', 'formatter': 'verbose', 'filename': '/tmp/debug.log', } }) # The default 'django' logger is a catch-all that does nothing. We replace it with # a rotating file handler. LOGGING['loggers'].update({ 'django': { 'handlers': ['rotate'], 'propagate': True, 'level': 'DEBUG', } }) # If you don't want to completely replace the django handler, you could do something # like this instead: #LOGGING['loggers']['django']['handlers'] += ['rotate']
This will add your rotating file handler to existing handlers, identify the basic formatting elements, and replace the logger of all traps (which does nothing) with the one that replaces the default logger
dwurf source share