Getting a TimedRotatingFileHandler not to put two dates in the same file?

wrw at mac.com wrw at mac.com
Wed Oct 24 11:38:42 EDT 2012


On Oct 24, 2012, at 10:22 AM, David M Chess <chess at us.ibm.com> wrote:

> >> This works great, splitting the log information across files by date, as 
> >> long as the process is actually up at midnight.
> >>
> >> But now the users have noticed that if the process isn't up at midnight, 
> >> they can end up with lines from two (or I guess potentially more) dates in 
> >> the same log file.
> >>
> >> Is there some way to fix this, either with cleverer arguments into the 
> >> TimedRotatingFileHandler, or by some plausible subclassing of it or its 
> >> superclass? 
> 
> Tx, 
> DC 


(After a VERY brief scan of the logging cookbook and modules.)
I don't think you have any choice but brute force.  If the program
wasn't up at midnight, then somehow it got restarted. You will have
to add logic to the restart code (or to the program itself that gets
run as it initializes).

Something like:

Does a log file exist? -> No ->  First run; create log file & continue
          |
         Yes
          |
  Read backwards looking for date change, copy lines after change
  to new file, delete from old file.

-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121024/0e08fcd9/attachment.html>


More information about the Python-list mailing list