##// END OF EJS Templates
blackbox: avoid creating multiple file handles for a single log...
timeless -
r28243:45313f5a default
parent child Browse files
Show More
@@ -49,6 +49,21 command = cmdutil.command(cmdtable)
49 testedwith = 'internal'
49 testedwith = 'internal'
50 lastblackbox = None
50 lastblackbox = None
51
51
52 filehandles = {}
53
54 def _openlog(vfs):
55 path = vfs.join('blackbox.log')
56 if path in filehandles:
57 return filehandles[path]
58 filehandles[path] = fp = vfs('blackbox.log', 'a')
59 return fp
60
61 def _closelog(vfs):
62 path = vfs.join('blackbox.log')
63 fp = filehandles[path]
64 del filehandles[path]
65 fp.close()
66
52 def wrapui(ui):
67 def wrapui(ui):
53 class blackboxui(ui.__class__):
68 class blackboxui(ui.__class__):
54 @util.propertycache
69 @util.propertycache
@@ -71,20 +86,20 def wrapui(ui):
71 self.debug("warning: cannot rename '%s' to '%s': %s\n" %
86 self.debug("warning: cannot rename '%s' to '%s': %s\n" %
72 (newpath, oldpath, err.strerror))
87 (newpath, oldpath, err.strerror))
73
88
74 fp = self._bbvfs('blackbox.log', 'a')
89 fp = _openlog(self._bbvfs)
75 maxsize = self.configbytes('blackbox', 'maxsize', 1048576)
90 maxsize = self.configbytes('blackbox', 'maxsize', 1048576)
76 if maxsize > 0:
91 if maxsize > 0:
77 st = self._bbvfs.fstat(fp)
92 st = self._bbvfs.fstat(fp)
78 if st.st_size >= maxsize:
93 if st.st_size >= maxsize:
79 path = fp.name
94 path = fp.name
80 fp.close()
95 _closelog(self._bbvfs)
81 maxfiles = self.configint('blackbox', 'maxfiles', 7)
96 maxfiles = self.configint('blackbox', 'maxfiles', 7)
82 for i in xrange(maxfiles - 1, 1, -1):
97 for i in xrange(maxfiles - 1, 1, -1):
83 rotate(oldpath='%s.%d' % (path, i - 1),
98 rotate(oldpath='%s.%d' % (path, i - 1),
84 newpath='%s.%d' % (path, i))
99 newpath='%s.%d' % (path, i))
85 rotate(oldpath=path,
100 rotate(oldpath=path,
86 newpath=maxfiles > 0 and path + '.1')
101 newpath=maxfiles > 0 and path + '.1')
87 fp = self._bbvfs('blackbox.log', 'a')
102 fp = _openlog(self._bbvfs)
88 return fp
103 return fp
89
104
90 def log(self, event, *msg, **opts):
105 def log(self, event, *msg, **opts):
General Comments 0
You need to be logged in to leave comments. Login now