Django 1.3 logging timedrottingfilehandler truncating file every time

I am using the django 1.3 logging function and trying to implement a timedrotatingfilehandler to rotate logs every hour. The logger works with the ability to rotate every hour, but it seems that during each log request it truncates the file. The file has only the last message written. This is a problem in the django handler or I am missing somewhere. Registration Dictionary below:

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
    'standard': {
        'format' : "%(asctime)s:%(pathname)s:%(lineno)s: %(message)s",
        'datefmt' : "%d/%b/%Y %H:%M:%S"
    },
},
'handlers': {
    'logfile': {
        'level':'DEBUG',
        'class':'logging.handlers.TimedRotatingFileHandler',
        'filename': "/tmp/log1.log",
    'when' : 'hour',
    'interval' : 0,
        'formatter': 'standard',
    },
},
'loggers': {
    'collection': {
        'handlers': ['logfile'],
        'level': 'DEBUG',
    },
}
}

Please note: when the interval is set to 1, the log does not rotate. Is this a bug in django?

+3
source share
3 answers

You need to install:

'when' : 'H',
'interval' : 1,

From the code current events are supported "when":

  • S - Seconds
  • M - Minutes
  • H - Watch
  • D - Days
  • -
  • W {0-6} - ; 0 -

- (, == 'H' == 2 2 ).

+1

, , . , .

0

I think there are several processes in your log file, in which case you can use ConcurrentLogHandler to avoid truncation.

0
source

All Articles