Reputation: 5540
I am using django 1.3's logging feature and trying to implement a timedrotatingfilehandler to rotate logs every hour.The logger is rotating successfully after every hour but it seems during every log request it truncates the file.The file has only the last written message.Is this an issue in django handler or am i missing somewhere.The logging dictionary is 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 is not getting rotated.Is this a bug in django?
Upvotes: 3
Views: 2819
Reputation: 4535
I guess there are multiple processes writing to your log file, in which case you can use ConcurrentLogHandler to avoid truncating.
Upvotes: 0
Reputation: 1298
Whenever you are creating a log file, just add a datetime stamp to the filename. This will make sure that the file will never be truncated.
Upvotes: 0
Reputation: 9825
You need to set:
'when' : 'H',
'interval' : 1,
From the code, current 'when' events supported:
Interval is the number of intervals to count (e.g. when == 'H' and interval == 2 will result in 2 hours).
Upvotes: 1