cpython: 6d61b057c375 (original) (raw)
Mercurial > cpython
changeset 98468:6d61b057c375
Closes #24884: refactored WatchedFileHandler file reopening into a separate method, based on a suggestion and patch by Marian Horban. [#24884]
Vinay Sajip <vinay_sajip@yahoo.co.uk> | |
---|---|
date | Thu, 01 Oct 2015 20:54:41 +0100 |
parents | 757baaedc043 |
children | 2b5357b38366 |
files | Doc/library/logging.handlers.rst Lib/logging/handlers.py |
diffstat | 2 files changed, 21 insertions(+), 6 deletions(-)[+] [-] Doc/library/logging.handlers.rst 12 Lib/logging/handlers.py 15 |
line wrap: on
line diff
--- a/Doc/library/logging.handlers.rst
+++ b/Doc/library/logging.handlers.rst
@@ -162,11 +162,17 @@ for this value.
first call to :meth:emit
. By default, the file grows indefinitely.
- .. method:: reopenIfNeeded() +
Checks to see if the file has changed. If it has, the existing stream is[](#l1.9)
flushed and closed and the file opened again, typically as a precursor to[](#l1.10)
outputting the record to the file.[](#l1.11)
Outputs the record to the file, but first checks to see if the file has[](#l1.16)
changed. If it has, the existing stream is flushed and closed and the[](#l1.17)
file opened again, before outputting the record to the file.[](#l1.18)
Outputs the record to the file, but first calls :meth:`reopenIfNeeded` to[](#l1.19)
reopen the file if it has changed.[](#l1.20)
--- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -440,11 +440,11 @@ class WatchedFileHandler(logging.FileHan sres = os.fstat(self.stream.fileno()) self.dev, self.ino = sres[ST_DEV], sres[ST_INO]
Emit a record.[](#l2.10)
Reopen log file if needed.[](#l2.11)
First check if the underlying file has changed, and if it[](#l2.13)
Checks if the underlying file has changed, and if it[](#l2.14) has, close the old stream and reopen the file to get the[](#l2.15) current stream.[](#l2.16) """[](#l2.17)
@@ -467,6 +467,15 @@ class WatchedFileHandler(logging.FileHan # open a new file handle and get new stat info from that fd self.stream = self._open() self._statstream() +
If underlying file has changed, reopen the file before emitting the[](#l2.27)
record to it.[](#l2.28)
"""[](#l2.29)
self.reopenIfNeeded()[](#l2.30) logging.FileHandler.emit(self, record)[](#l2.31)