##// END OF EJS Templates
blackbox: fix rotation with chg...
Jun Wu -
r34109:4f60720c default
parent child Browse files
Show More
@@ -73,21 +73,6 b" configitem('blackbox', 'logsource',"
73 73
74 74 lastui = None
75 75
76 filehandles = {}
77
78 def _openlog(vfs):
79 path = vfs.join('blackbox.log')
80 if path in filehandles:
81 return filehandles[path]
82 filehandles[path] = fp = vfs('blackbox.log', 'a')
83 return fp
84
85 def _closelog(vfs):
86 path = vfs.join('blackbox.log')
87 fp = filehandles[path]
88 del filehandles[path]
89 fp.close()
90
91 76 def wrapui(ui):
92 77 class blackboxui(ui.__class__):
93 78 def __init__(self, src=None):
@@ -132,21 +117,23 b' def wrapui(ui):'
132 117 self.debug("warning: cannot rename '%s' to '%s': %s\n" %
133 118 (newpath, oldpath, err.strerror))
134 119
135 fp = _openlog(self._bbvfs)
136 120 maxsize = self.configbytes('blackbox', 'maxsize')
121 name = 'blackbox.log'
137 122 if maxsize > 0:
138 st = self._bbvfs.fstat(fp)
139 if st.st_size >= maxsize:
140 path = fp.name
141 _closelog(self._bbvfs)
142 maxfiles = self.configint('blackbox', 'maxfiles', 7)
143 for i in xrange(maxfiles - 1, 1, -1):
144 rotate(oldpath='%s.%d' % (path, i - 1),
145 newpath='%s.%d' % (path, i))
146 rotate(oldpath=path,
147 newpath=maxfiles > 0 and path + '.1')
148 fp = _openlog(self._bbvfs)
149 return fp
123 try:
124 st = self._bbvfs.stat(name)
125 except OSError:
126 pass
127 else:
128 if st.st_size >= maxsize:
129 path = self._bbvfs.join(name)
130 maxfiles = self.configint('blackbox', 'maxfiles', 7)
131 for i in xrange(maxfiles - 1, 1, -1):
132 rotate(oldpath='%s.%d' % (path, i - 1),
133 newpath='%s.%d' % (path, i))
134 rotate(oldpath=path,
135 newpath=maxfiles > 0 and path + '.1')
136 return self._bbvfs(name, 'a')
150 137
151 138 def _bbwrite(self, fmt, *args):
152 139 self._bbfp.write(fmt % args)
@@ -230,3 +230,57 b' Test log recursion from dirty status che'
230 230
231 231 cleanup
232 232 $ cd ..
233
234 #if chg
235
236 when using chg, blackbox.log should get rotated correctly
237
238 $ cat > $TESTTMP/noop.py << EOF
239 > from __future__ import absolute_import
240 > import time
241 > from mercurial import registrar, scmutil
242 > cmdtable = {}
243 > command = registrar.command(cmdtable)
244 > @command('noop')
245 > def noop(ui, repo):
246 > pass
247 > EOF
248
249 $ hg init blackbox-chg
250 $ cd blackbox-chg
251
252 $ cat > .hg/hgrc << EOF
253 > [blackbox]
254 > maxsize = 500B
255 > [extensions]
256 > # extension change forces chg to restart
257 > noop=$TESTTMP/noop.py
258 > EOF
259
260 $ $PYTHON -c 'print("a" * 400)' > .hg/blackbox.log
261 $ chg noop
262 $ chg noop
263 $ chg noop
264 $ chg noop
265 $ chg noop
266
267 $ cat > showsize.py << 'EOF'
268 > import os, sys
269 > limit = 500
270 > for p in sys.argv[1:]:
271 > size = os.stat(p).st_size
272 > if size >= limit:
273 > desc = '>='
274 > else:
275 > desc = '<'
276 > print('%s: %s %d' % (p, desc, limit))
277 > EOF
278
279 $ $PYTHON showsize.py .hg/blackbox*
280 .hg/blackbox.log: < 500
281 .hg/blackbox.log.1: >= 500
282 .hg/blackbox.log.2: >= 500
283
284 $ cd ..
285
286 #endif
General Comments 0
You need to be logged in to leave comments. Login now