[Django]-Django logging: Cannot create logs per day

10👍

Don’t set the date there: it’ll be evaluated at import time only.

Instead, use logging.TimedRotatingFileHandler, which adds the timestamp for you automatically, like this:

LOGGING = {
    # ...
    'handlers': {
        'file': {
            'level': 'INFO',
            'formatter': 'verbose',
            'filename': os.path.join(FOOBAR, 'foobar.log'),
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'when': 'midnight',
            'interval': 1,
        },
    },
}

Leave a comment