##// 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 b' command = cmdutil.command(cmdtable)'
49 49 testedwith = 'internal'
50 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 67 def wrapui(ui):
53 68 class blackboxui(ui.__class__):
54 69 @util.propertycache
@@ -71,20 +86,20 b' def wrapui(ui):'
71 86 self.debug("warning: cannot rename '%s' to '%s': %s\n" %
72 87 (newpath, oldpath, err.strerror))
73 88
74 fp = self._bbvfs('blackbox.log', 'a')
89 fp = _openlog(self._bbvfs)
75 90 maxsize = self.configbytes('blackbox', 'maxsize', 1048576)
76 91 if maxsize > 0:
77 92 st = self._bbvfs.fstat(fp)
78 93 if st.st_size >= maxsize:
79 94 path = fp.name
80 fp.close()
95 _closelog(self._bbvfs)
81 96 maxfiles = self.configint('blackbox', 'maxfiles', 7)
82 97 for i in xrange(maxfiles - 1, 1, -1):
83 98 rotate(oldpath='%s.%d' % (path, i - 1),
84 99 newpath='%s.%d' % (path, i))
85 100 rotate(oldpath=path,
86 101 newpath=maxfiles > 0 and path + '.1')
87 fp = self._bbvfs('blackbox.log', 'a')
102 fp = _openlog(self._bbvfs)
88 103 return fp
89 104
90 105 def log(self, event, *msg, **opts):
General Comments 0
You need to be logged in to leave comments. Login now