Dear mailing list, I'm using the logging module and write my log messages via the FileHandler. I just realized that using an external log rotation mechanism does not work. That is, new messages are not added to the file after rotation. In my opinion external log rotate mechanisms should work with the standard file handler. websearch pointed me to TimedRotatingFileHandler . But this only seems like a workaround. For instance I would like to get my log file mailed once a week. But it seems difficult to sync the cron job doing this and the logging-rotation mechanism. I think TimedRotatingFileHandler is important, e.g. for windows users. But for *nux users this seems to be unnecessary. Just want to gather some opinions before filing a bug. Regards, Matthias
On Sun, Nov 25, 2012 at 01:14:11PM +0100, Matthias Bernt <MatatTHC@gmx.de> wrote:
I'm using the logging module and write my log messages via the FileHandler. I just realized that using an external log rotation mechanism does not work. That is, new messages are not added to the file after rotation.
An external log rotation mechanism ought to send a signal to the application and the application ought to close and reopen logs. That is, this is an application-level problem, not logging module-level. Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.
On Sun, Nov 25, 2012 at 9:02 AM, Oleg Broytman <phd@phdru.name> wrote:
On Sun, Nov 25, 2012 at 01:14:11PM +0100, Matthias Bernt <MatatTHC@gmx.de> wrote:
I'm using the logging module and write my log messages via the FileHandler. I just realized that using an external log rotation mechanism does not work. That is, new messages are not added to the file after rotation.
An external log rotation mechanism ought to send a signal to the application and the application ought to close and reopen logs. That is, this is an application-level problem, not logging module-level.
I'm not so sure. Logging ought to "just work" without the application having to do much about it the details. Log rotation is definitely a useful feature; I've run into this very issue before and never found a satisfactory solution. Surely it should be possible for the file handler to occasionally stat() its output file by name and compare that to fstat() for the file descriptor and if they differ, reopen? -- --Guido van Rossum (python.org/~guido)
On 2012-11-25, at 18:02 , Oleg Broytman wrote:
On Sun, Nov 25, 2012 at 01:14:11PM +0100, Matthias Bernt <MatatTHC@gmx.de> wrote:
I'm using the logging module and write my log messages via the FileHandler. I just realized that using an external log rotation mechanism does not work. That is, new messages are not added to the file after rotation.
An external log rotation mechanism ought to send a signal to the application and the application ought to close and reopen logs. That is, this is an application-level problem, not logging module-level.
I don't know that FileHandler officially supports reopening its underlying file. On the other hand, WatchedFileHandler[0] does exactly that and is specifically advertised for use with external log rotators:
WatchedFileHandler […] watches the file it is logging to. If the file changes, it is closed and reopened using the file name.
A file change can happen because of usage of programs such as newsyslog and logrotate which perform log file rotation. […] If the file has changed, the old file stream is closed, and the file opened to get a new stream.
[0] http://docs.python.org/2/library/logging.handlers.html#watchedfilehandler
participants (4)
-
Guido van Rossum
-
Matthias Bernt
-
Oleg Broytman
-
Xavier Morel