diff --git a/hgext/blackbox.py b/hgext/blackbox.py --- a/hgext/blackbox.py +++ b/hgext/blackbox.py @@ -10,9 +10,16 @@ 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; -this takes a list of regular expressions. As a special rule, if any item in the -list is the string '*', everything is logged (default: '*'). +The events that get logged can be configured via the blackbox.track and +blackbox.notrack config keys; these take a list of regular expressions. If an +event matches an item in blackbox.notrack, it is not logged, otherwise if it +matches an item in blackbox.track, it is logged. + +If blackbox.track contains an item that is just '*', blackbox.track matches +everything (but blackbox.notrack still takes precedence). + +By default, blackbox.track=* and blackbox.untrack is empty, causing all events +to be logged. Examples:: @@ -29,11 +36,18 @@ # log every event starting with 'command' (including 'command' itself), and # everything ending with 'hook' (including 'hook' itself). track = command.*, .*hook + # explicitly ignore pythonhook + notrack = pythonhook [blackbox] track = incoming [blackbox] + # track = * is the default, so doesn't need to be specified here; + # this ignores events ending with 'hook' (and 'hook' itself) + notrack = .*hook + + [blackbox] # limit the size of a log file maxsize = 1.5 MB # rotate up to N log files when the current one gets too big @@ -90,6 +104,9 @@ configitem('blackbox', 'track', default=lambda: ['*'], ) +configitem('blackbox', 'notrack', + default=lambda: [], +) configitem('blackbox', 'date-format', default='%Y/%m/%d %H:%M:%S', ) @@ -111,12 +128,26 @@ except re.error as e: ui.warn(_('invalid blackbox.track setting: %s\n') % e) self._active = False + + self._notrackedevents = None + notrack = ui.configlist('blackbox', 'notrack') + if notrack: # re.compile('').match matches *everything* + try: + self._notrackedevents = re.compile(br'|'.join(notrack)) + except re.error as e: + # logging too much is usually less of a problem, so we just + # (mostly) silently accept this. + ui.debug('invalid blackbox.notrack setting: %s\n' % e) + self._maxfiles = ui.configint('blackbox', 'maxfiles') self._maxsize = ui.configbytes('blackbox', 'maxsize') self._inlog = False def tracked(self, event): - return self._active and self._trackedevents.match(event) + return (self._active and + (not self._notrackedevents or + not self._notrackedevents.match(event)) and + self._trackedevents.match(event)) def log(self, ui, event, msg, opts): # self._log() -> ctx.dirty() may create new subrepo instance, which diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t --- a/tests/test-blackbox.t +++ b/tests/test-blackbox.t @@ -396,6 +396,47 @@ invalid blackbox.track setting: nothing to repeat $ cd $TESTTMP +test blackbox.notrack setting + +(test that setting this on the commandline works, and doesn't record the 'init' +command) + $ hg --config blackbox.track='*' \ + > --config blackbox.notrack='.*' \ + > init test_notrack + $ cd test_notrack + $ cat >> .hg/hgrc << EOF + > [blackbox] + > logsource = True + > # a rather odd way of writing 'track = command' :) + > track = command.* + > notrack = comand..* + > EOF +(this should only have 'command', and not have 'commandfinish' or others) + $ hg blackbox + 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000) [command]> blackbox + $ cd $TESTTMP + +invalid regex entries in blackbox.notrack cause it to be silently ignored + + $ hg --config blackbox.track='command.*' \ + > --config blackbox.notrack=')' \ + > init test_notrack_invalid + $ cd test_notrack_invalid + $ cat >> .hg/hgrc << EOF + > [blackbox] + > logsource = True + > track = command.* + > # invalid: "nothing to repeat" + > notrack = comand..** + > [alias] + > blackboxalias = blackbox + > EOF + $ hg blackboxalias + 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> --config 'blackbox.track=command.*' --config 'blackbox.notrack=)' init test_notrack_invalid exited 0 after * seconds (glob) + 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000) [command]> blackboxalias + 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000) [commandalias]> alias 'blackboxalias' expands to 'blackbox' + $ cd $TESTTMP + #if chg when using chg, blackbox.log should get rotated correctly