diff -r b42f6c930cea Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst Tue Aug 18 00:35:52 2015 -0700 +++ b/Doc/library/logging.handlers.rst Tue Aug 18 05:02:56 2015 -0400 @@ -162,11 +162,17 @@ first call to :meth:`emit`. By default, the file grows indefinitely. + .. method:: reopenFile() + + Checks to see if the file has changed. If it has, the existing stream is + flushed and closed and the file opened again, before outputting the record + to the file. + + .. method:: emit(record) - Outputs the record to the file, but first checks to see if the file has - changed. If it has, the existing stream is flushed and closed and the - file opened again, before outputting the record to the file. + Outputs the record to the file, but first calls reopenFile method to reopen + file if it has changed. .. _base-rotating-handler: diff -r b42f6c930cea Lib/logging/handlers.py --- a/Lib/logging/handlers.py Tue Aug 18 00:35:52 2015 -0700 +++ b/Lib/logging/handlers.py Tue Aug 18 05:02:56 2015 -0400 @@ -440,11 +440,11 @@ sres = os.fstat(self.stream.fileno()) self.dev, self.ino = sres[ST_DEV], sres[ST_INO] - def emit(self, record): + def reopenFile(self): """ - Emit a record. + Reopen log file. - First check if the underlying file has changed, and if it + Check if the underlying file has changed, and if it has, close the old stream and reopen the file to get the current stream. """ @@ -467,6 +467,14 @@ # open a new file handle and get new stat info from that fd self.stream = self._open() self._statstream() + + def emit(self, record): + """ + Emit a record. + + If underlying file has changed reopen file before emitting. + """ + self.reopenFile() logging.FileHandler.emit(self, record)