Re: Getting a TimedRotatingFileHandler not to put two dates in the same file?
> w...@mac.com > 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. Yep, I'm concluding that also. It just wasn't clear to me from the documentation whether or not the existing TimedRotatingFileHandler had any "at startup, see if we missed any rollovers, and do them now if so" function, or if there was some known variant that does. The answer, apparently, being "nope". :) Shouldn't be that hard to write, so that's probably what we'll do. DC --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a TimedRotatingFileHandler not to put two dates in the same file?
On Oct 24, 2012, at 10:22 AM, David M Chess 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a TimedRotatingFileHandler not to put two dates in the same file?
David M Chess us.ibm.com> writes: > >> 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? Well, of course you can subclass and override it to do what you want - there's no magic there. The behaviour is as you would expect: the default behaviour of a TimedRotatingFileHandler is to append, and roll over at midnight. So if your program isn't running at midnight, it won't rotate: Day 1. Run your program, stop it before midnight. The log file contains dates from this day. No rotation occurred. Day 2. Run your program again, stop it before midnight. The log file contains dates from this day, and Day 1. No rotation occurred. That's the symptom you're seeing, right? You could do as Dave Angel suggested - just use a FileHandler with the name derived from the date. If you don't want to or can't actually rotate files at midnight, you're using the wrong tool for the job :-) If you sometimes want to rotate at midnight (the process is running at that time) and at other times not (the process isn't running then), you might have to code startup logic in your program to deal with the vagaries of your environment, since only you would know what they are :-) Work is afoot to make the actual rollover time configurable (i.e. not forced to be literally midnight) - see http://bugs.python.org/issue9556 - but that's an enhancement request, not a bug, and so it'll see the light of day in Python 3.4, if at all. An implementation is in my sandbox repo at http://hg.python.org/sandbox/vsajip in branch fix9556. If all you need to do is rollover at a different time daily (say 7 a.m.), you might be able to use this. Feel free to use that code as inspiration for your subclass. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a TimedRotatingFileHandler not to put two dates in the same file?
> d...@davea.name > > On 10/23/2012 11:23 AM, David M Chess wrote: > > We have a TimedRotatingFileHandler with when='midnight' > > You give us no clue what's in this class, or how it comes up with the > filenames used. Sorry if I was unclear. This isn't my own subclass of TimedRotatingFileHandler or anything, this is the bog-standard logging.handlers.TimedRotatingFileHandler I'm talking about. So all clues about what's in the class, and how it comes up with the filenames used, is available at http://docs.python.org/library/logging.handlers.html#timedrotatingfilehandler :) The specific Python version involved here is Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32), to the extent that that matters... >> 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 http://mail.python.org/mailman/listinfo/python-list
Re: Getting a TimedRotatingFileHandler not to put two dates in the same file?
On 10/23/2012 11:23 AM, David M Chess wrote: > We have a TimedRotatingFileHandler with when='midnight' You give us no clue what's in this class, or how it comes up with the filenames used. > . > > 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? Why not use the date itself to derive the filename? And check whether the date has changed since the last update, and if so, close and reopen. Midnight is irrelevant. > Or am I misinterpreting the symptoms somehow? > > Tx much! > DC > > -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Getting a TimedRotatingFileHandler not to put two dates in the same file?
We have a TimedRotatingFileHandler with when='midnight'. 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? Or am I misinterpreting the symptoms somehow? Tx much! DC -- http://mail.python.org/mailman/listinfo/python-list