summaryrefslogtreecommitdiffstats
path: root/Lib/logging/handlers.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2015-10-01 19:54:41 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2015-10-01 19:54:41 (GMT)
commit29a1445136c7353543b516a085c38b8be9ce5109 (patch)
treeae7d7ccce28f5a8f101839ad888b8ed66189c560 /Lib/logging/handlers.py
parent14b1b486ca96745485e4c6c71eefa56372e815d3 (diff)
downloadcpython-29a1445136c7353543b516a085c38b8be9ce5109.zip
cpython-29a1445136c7353543b516a085c38b8be9ce5109.tar.gz
cpython-29a1445136c7353543b516a085c38b8be9ce5109.tar.bz2
Closes #24884: refactored WatchedFileHandler file reopening into a separate method, based on a suggestion and patch by Marian Horban.
Diffstat (limited to 'Lib/logging/handlers.py')
-rw-r--r--Lib/logging/handlers.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 02a5fc1..54bee89 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -440,11 +440,11 @@ class WatchedFileHandler(logging.FileHandler):
sres = os.fstat(self.stream.fileno())
self.dev, self.ino = sres[ST_DEV], sres[ST_INO]
- def emit(self, record):
+ def reopenIfNeeded(self):
"""
- Emit a record.
+ Reopen log file if needed.
- First check if the underlying file has changed, and if it
+ Checks 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,15 @@ class WatchedFileHandler(logging.FileHandler):
# 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 the file before emitting the
+ record to it.
+ """
+ self.reopenIfNeeded()
logging.FileHandler.emit(self, record)