D5786: blackbox: support blackbox.notrack regex patterns to exclude tracking events
spectral (Kyle Lippincott)
phabricator at mercurial-scm.org
Thu Jan 31 22:07:30 UTC 2019
spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5786
AFFECTED FILES
hgext/blackbox.py
tests/test-blackbox.t
CHANGE DETAILS
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,26 @@
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
+
#if chg
when using chg, blackbox.log should get rotated correctly
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,27 @@
except re.error as e:
ui.warn('invalid blackbox.track setting: %s\n' % e)
self._active = False
+
+ notrack = ui.configlist('blackbox', 'notrack')
+ if notrack:
+ 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)
+ else:
+ self._notrackedevents = None
+
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
To: spectral, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list