I have log handlers configured to rotate at midnight:
'request_handler': {
'level': 'DEBUG',
'class': 'logging.handlers.TimedRotatingFileHandler',
'when': 'midnight',
'interval': 1,
'filename': os.path.join(LOG_ROOT, 'django_request.log'),
'backupCount': 30,
'formatter': 'standard',
},
Also have cron job to archive/purge logs with command, which runs at 01:00 every day (crontab -e -> "0 1 * * * /cronscripts/archive_logs.sh"):
gzip --quiet *\.log\.[0-9]*
find $LOGS_DIR -mtime +$LOGS_KEEP_DAYS -exec rm {} \;
With that configuration log files get truncated by some reason, here description:
- Rotated log django_request.log.2014-09-30 will have records from 00:00 to ~2:30 (the end time can vary a bit)
- Meanwhile django_request.log before rotation has records after 02:30
- django_request.log.2014-09-30 file has records dated 1-th of Oct instead of 30-th of Sep
Example:
alex@localhost$ tail django_request.log.2014-09-30
2014-10-01 02:02:48,562 [WARNING] django.request: Not Found: /admin_media/i...
Are there any ideas what's wrong? Django is running with apache/mod_wsgi.