0

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:

  1. Rotated log django_request.log.2014-09-30 will have records from 00:00 to ~2:30 (the end time can vary a bit)
  2. Meanwhile django_request.log before rotation has records after 02:30
  3. 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.

ZAN
  • 561
  • 1
  • 4
  • 16
  • 1
    Are multiple processes writing to the logs? Perhaps the solution to the following question would work http://stackoverflow.com/questions/18840785/timedrotatingfilehandler-doesnt-work-fine-in-django-with-multi-instance – AndrewS Oct 01 '14 at 12:14
  • Yes, there are several apache processes accessing logs. Will try the solution, thanks! – ZAN Oct 01 '14 at 12:35
  • You are right - using log locking solved the problem, thanks! – ZAN Oct 03 '14 at 13:41

0 Answers0