forked from fedora-python/python26
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-2.6.6-logging-watchedfilehandler.patch
67 lines (63 loc) · 2.54 KB
/
python-2.6.6-logging-watchedfilehandler.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- Python-2.6.6/Lib/logging/handlers.py.orig 2013-06-14 09:00:56.546579086 +0200
+++ Python-2.6.6/Lib/logging/handlers.py 2013-06-14 09:13:48.720357480 +0200
@@ -24,7 +24,7 @@
To use, simply 'import logging.handlers' and log away!
"""
-import logging, socket, types, os, string, cPickle, struct, time, re
+import errno, logging, socket, types, os, string, cPickle, struct, time, re
from stat import ST_DEV, ST_INO
try:
@@ -375,11 +375,13 @@
"""
def __init__(self, filename, mode='a', encoding=None, delay=0):
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
- if not os.path.exists(self.baseFilename):
- self.dev, self.ino = -1, -1
- else:
- stat = os.stat(self.baseFilename)
- self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
+ self.dev, self.ino = -1, -1
+ self._statstream()
+
+ def _statstream(self):
+ if self.stream:
+ sres = os.fstat(self.stream.fileno())
+ self.dev, self.ino = sres[ST_DEV], sres[ST_INO]
def emit(self, record):
"""
@@ -389,19 +391,23 @@
has, close the old stream and reopen the file to get the
current stream.
"""
- if not os.path.exists(self.baseFilename):
- stat = None
- changed = 1
- else:
- stat = os.stat(self.baseFilename)
- changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino)
- if changed and self.stream is not None:
- self.stream.flush()
- self.stream.close()
- self.stream = self._open()
- if stat is None:
- stat = os.stat(self.baseFilename)
- self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
+ try:
+ # stat the file by path, checking for existence
+ sres = os.stat(self.baseFilename)
+ except OSError as err:
+ if err.errno == errno.ENOENT:
+ sres = None
+ else:
+ raise
+ # compare file system stat with that of our stream file handle
+ if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino:
+ if self.stream is not None:
+ # we have an open file handle, clean it up
+ self.stream.flush()
+ self.stream.close()
+ # open new file handle and get new stat info from that fd
+ self.stream = self._open()
+ self._statstream()
logging.FileHandler.emit(self, record)
class SocketHandler(logging.Handler):