##// END OF EJS Templates
blackbox: just try writing to repo.vfs and update lastlogger on success...
Yuya Nishihara -
r40828:ea2688c8 default
parent child Browse files
Show More
@@ -121,7 +121,7 b' def _openlogfile(ui, vfs):'
121 newpath='%s.%d' % (path, i))
121 newpath='%s.%d' % (path, i))
122 rotate(oldpath=path,
122 rotate(oldpath=path,
123 newpath=maxfiles > 0 and path + '.1')
123 newpath=maxfiles > 0 and path + '.1')
124 return vfs(name, 'a')
124 return vfs(name, 'a', makeparentdirs=False)
125
125
126 class proxylogger(object):
126 class proxylogger(object):
127 """Forward log events to another logger to be set later"""
127 """Forward log events to another logger to be set later"""
@@ -143,22 +143,10 b' class blackboxlogger(object):'
143 self._repo = repo
143 self._repo = repo
144 self._trackedevents = set(ui.configlist('blackbox', 'track'))
144 self._trackedevents = set(ui.configlist('blackbox', 'track'))
145
145
146 @property
147 def _bbvfs(self):
148 vfs = self._repo.vfs
149 if not vfs.isdir('.'):
150 vfs = None
151 return vfs
152
153 def tracked(self, event):
146 def tracked(self, event):
154 return b'*' in self._trackedevents or event in self._trackedevents
147 return b'*' in self._trackedevents or event in self._trackedevents
155
148
156 def log(self, ui, event, msg, opts):
149 def log(self, ui, event, msg, opts):
157 if self._bbvfs:
158 _lastlogger.logger = self
159 else:
160 return
161
162 default = ui.configdate('devel', 'default-date')
150 default = ui.configdate('devel', 'default-date')
163 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
151 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
164 user = procutil.getuser()
152 user = procutil.getuser()
@@ -178,13 +166,15 b' class blackboxlogger(object):'
178 try:
166 try:
179 fmt = '%s %s @%s%s (%s)%s> %s'
167 fmt = '%s %s @%s%s (%s)%s> %s'
180 args = (date, user, rev, changed, pid, src, msg)
168 args = (date, user, rev, changed, pid, src, msg)
181 with _openlogfile(ui, self._bbvfs) as fp:
169 with _openlogfile(ui, self._repo.vfs) as fp:
182 fp.write(fmt % args)
170 fp.write(fmt % args)
183 except (IOError, OSError) as err:
171 except (IOError, OSError) as err:
184 # deactivate this to avoid failed logging again
172 # deactivate this to avoid failed logging again
185 self._trackedevents.clear()
173 self._trackedevents.clear()
186 ui.debug('warning: cannot write to blackbox.log: %s\n' %
174 ui.debug('warning: cannot write to blackbox.log: %s\n' %
187 encoding.strtolocal(err.strerror))
175 encoding.strtolocal(err.strerror))
176 return
177 _lastlogger.logger = self
188
178
189 def uipopulate(ui):
179 def uipopulate(ui):
190 ui.setlogger(b'blackbox', _lastlogger)
180 ui.setlogger(b'blackbox', _lastlogger)
@@ -327,6 +327,29 b' Test log recursion from dirty status che'
327 cleanup
327 cleanup
328 $ cd ..
328 $ cd ..
329
329
330 Test missing log directory, which shouldn't be created automatically
331
332 $ cat <<'EOF' > closeremove.py
333 > def reposetup(ui, repo):
334 > class rmrepo(repo.__class__):
335 > def close(self):
336 > super(rmrepo, self).close()
337 > self.ui.debug(b'removing %s\n' % self.vfs.base)
338 > self.vfs.rmtree()
339 > repo.__class__ = rmrepo
340 > EOF
341
342 $ hg init gone
343 $ cd gone
344 $ cat <<'EOF' > .hg/hgrc
345 > [extensions]
346 > closeremove = ../closeremove.py
347 > EOF
348 $ hg log --debug
349 removing $TESTTMP/gone/.hg
350 warning: cannot write to blackbox.log: $ENOENT$
351 $ cd ..
352
330 #if chg
353 #if chg
331
354
332 when using chg, blackbox.log should get rotated correctly
355 when using chg, blackbox.log should get rotated correctly
General Comments 0
You need to be logged in to leave comments. Login now