def _log(self, ui, event, msg, opts): default = ui.configdate(b'devel', b'default-date') date = dateutil.datestr(default, ui.config(b'blackbox', b'date-format')) user = procutil.getuser() pid = b'%d' % procutil.getpid() changed = b'' ctx = self._repo[None] parents = ctx.parents() rev = b'+'.join([hex(p.node()) for p in parents]) if ui.configbool(b'blackbox', b'dirty') and ctx.dirty( missing=True, merge=False, branch=False): changed = b'+' if ui.configbool(b'blackbox', b'logsource'): src = b' [%s]' % event else: src = b'' try: fmt = b'%s %s @%s%s (%s)%s> %s' args = (date, user, rev, changed, pid, src, msg) with loggingutil.openlogfile( ui, self._repo.vfs, name=b'blackbox.log', maxfiles=self._maxfiles, maxsize=self._maxsize, ) as fp: fp.write(fmt % args) except (IOError, OSError) as err: # deactivate this to avoid failed logging again self._trackedevents.clear() ui.debug(b'warning: cannot write to blackbox.log: %s\n' % encoding.strtolocal(err.strerror)) return _lastlogger.logger = self
def log(self, event, *msg, **opts): global lastui super(blackboxui, self).log(event, *msg, **opts) if not '*' in self.track and not event in self.track: return if self._bbvfs: ui = self else: # certain ui instances exist outside the context of # a repo, so just default to the last blackbox that # was seen. ui = lastui if not ui: return vfs = ui._bbvfs if not vfs: return repo = getattr(ui, '_bbrepo', None) if not lastui or repo: lastui = ui if getattr(ui, '_bbinlog', False): # recursion and failure guard return ui._bbinlog = True default = self.configdate('devel', 'default-date') date = dateutil.datestr(default, '%Y/%m/%d %H:%M:%S') user = procutil.getuser() pid = '%d' % procutil.getpid() formattedmsg = msg[0] % msg[1:] rev = '(unknown)' changed = '' if repo: ctx = repo[None] parents = ctx.parents() rev = ('+'.join([hex(p.node()) for p in parents])) if (ui.configbool('blackbox', 'dirty') and ctx.dirty( missing=True, merge=False, branch=False)): changed = '+' if ui.configbool('blackbox', 'logsource'): src = ' [%s]' % event else: src = '' try: fmt = '%s %s @%s%s (%s)%s> %s' args = (date, user, rev, changed, pid, src, formattedmsg) with _openlogfile(ui, vfs) as fp: fp.write(fmt % args) except (IOError, OSError) as err: self.debug('warning: cannot write to blackbox.log: %s\n' % encoding.strtolocal(err.strerror)) # do not restore _bbinlog intentionally to avoid failed # logging again else: ui._bbinlog = False