diff --git a/hgext/blackbox.py b/hgext/blackbox.py --- a/hgext/blackbox.py +++ b/hgext/blackbox.py @@ -9,11 +9,15 @@ """log repository events to a blackbox for debugging Logs event information to .hg/blackbox.log to help debug and diagnose problems. -The events that get logged can be configured via the blackbox.track config key. + +The events that get logged can be configured via the blackbox.track config key; +this takes a list of regular expressions. As a special rule, if any item in the +list is the string '*', everything is logged (default: '*'). Examples:: [blackbox] + # log everything track = * # dirty is *EXPENSIVE* (slow); # each log entry indicates `+` if the repository is dirty, like :hg:`id`. @@ -22,7 +26,9 @@ logsource = True [blackbox] - track = command, commandfinish, commandexception, exthook, pythonhook + # log every event starting with 'command' (including 'command' itself), and + # everything ending with 'hook' (including 'hook' itself). + track = command.*, .*hook [blackbox] track = incoming @@ -93,13 +99,24 @@ class blackboxlogger(object): def __init__(self, ui, repo): self._repo = repo - self._trackedevents = set(ui.configlist('blackbox', 'track')) + self._active = True + track = ui.configlist('blackbox', 'track') + if not track: + self._active = False + elif b'*' in track: + self._trackedevents = re.compile(b'.*') + else: + try: + self._trackedevents = re.compile(b'|'.join(track)) + except re.error as e: + ui.warn(_('invalid blackbox.track setting: %s\n') % e) + self._active = False self._maxfiles = ui.configint('blackbox', 'maxfiles') self._maxsize = ui.configbytes('blackbox', 'maxsize') self._inlog = False def tracked(self, event): - return b'*' in self._trackedevents or event in self._trackedevents + return self._active and self._trackedevents.match(event) def log(self, ui, event, msg, opts): # self._log() -> ctx.dirty() may create new subrepo instance, which @@ -138,7 +155,7 @@ fp.write(fmt % args) except (IOError, OSError) as err: # deactivate this to avoid failed logging again - self._trackedevents.clear() + self._active = False ui.debug('warning: cannot write to blackbox.log: %s\n' % encoding.strtolocal(err.strerror)) return diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t --- a/tests/test-blackbox.t +++ b/tests/test-blackbox.t @@ -23,8 +23,8 @@ > confuse = log --limit 3 > so-confusing = confuse --style compact > [blackbox] - > track = backupbundle, branchcache, command, commandalias, commandexception, - > commandfinish, debug, exthook, incoming, pythonhook, tagscache + > track = backupbundle, branchcache, command.*, + > debug, exthook, incoming, pythonhook, tagscache > EOF $ hg init blackboxtest @@ -383,6 +383,19 @@ 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000) [command]> blackbox $ cd $TESTTMP +invalid regex entries in blackbox.track are interpreted as log nothing + + $ hg --config blackbox.track='**' init track_invalid_regex + invalid blackbox.track setting: nothing to repeat + $ cd track_invalid_regex + $ cat >> .hg/hgrc << EOF + > [blackbox] + > track = ** + > EOF + $ hg blackbox + invalid blackbox.track setting: nothing to repeat + $ cd $TESTTMP + #if chg when using chg, blackbox.log should get rotated correctly