##// END OF EJS Templates
logtoprocess: drop support for ui.log() call with invalid msg arguments (BC)...
Yuya Nishihara -
r40656:d2c997b8 default
parent child Browse files
Show More
@@ -9,21 +9,21 b''
9 This extension lets you specify a shell command per ui.log() event,
9 This extension lets you specify a shell command per ui.log() event,
10 sending all remaining arguments to as environment variables to that command.
10 sending all remaining arguments to as environment variables to that command.
11
11
12 Each positional argument to the method results in a `MSG[N]` key in the
12 Positional arguments construct a log message, which is passed in the `MSG1`
13 environment, starting at 1 (so `MSG1`, `MSG2`, etc.). Each keyword argument
13 environment variables. Each keyword argument is set as a `OPT_UPPERCASE_KEY`
14 is set as a `OPT_UPPERCASE_KEY` variable (so the key is uppercased, and
14 variable (so the key is uppercased, and prefixed with `OPT_`). The original
15 prefixed with `OPT_`). The original event name is passed in the `EVENT`
15 event name is passed in the `EVENT` environment variable, and the process ID
16 environment variable, and the process ID of mercurial is given in `HGPID`.
16 of mercurial is given in `HGPID`.
17
17
18 So given a call `ui.log('foo', 'bar', 'baz', spam='eggs'), a script configured
18 So given a call `ui.log('foo', 'bar %s\n', 'baz', spam='eggs'), a script
19 for the `foo` event can expect an environment with `MSG1=bar`, `MSG2=baz`, and
19 configured for the `foo` event can expect an environment with `MSG1=bar baz`,
20 `OPT_SPAM=eggs`.
20 and `OPT_SPAM=eggs`.
21
21
22 Scripts are configured in the `[logtoprocess]` section, each key an event name.
22 Scripts are configured in the `[logtoprocess]` section, each key an event name.
23 For example::
23 For example::
24
24
25 [logtoprocess]
25 [logtoprocess]
26 commandexception = echo "$MSG2$MSG3" > /var/log/mercurial_exceptions.log
26 commandexception = echo "$MSG1" > /var/log/mercurial_exceptions.log
27
27
28 would log the warning message and traceback of any failed command dispatch.
28 would log the warning message and traceback of any failed command dispatch.
29
29
@@ -60,25 +60,11 b' def uisetup(ui):'
60 """
60 """
61 script = self.config('logtoprocess', event)
61 script = self.config('logtoprocess', event)
62 if script:
62 if script:
63 if msg:
64 # try to format the log message given the remaining
65 # arguments
66 try:
67 # Format the message as blackbox does
68 formatted = msg[0] % msg[1:]
69 except (TypeError, KeyError):
70 # Failed to apply the arguments, ignore
71 formatted = msg[0]
72 messages = (formatted,) + msg[1:]
73 else:
74 messages = msg
75 env = {
63 env = {
76 b'EVENT': event,
64 b'EVENT': event,
77 b'HGPID': os.getpid(),
65 b'HGPID': os.getpid(),
66 b'MSG1': msg[0] % msg[1:],
78 }
67 }
79 # positional arguments are listed as MSG[N] keys in the
80 # environment
81 env.update((b'MSG%d' % i, m) for i, m in enumerate(messages, 1))
82 # keyword arguments get prefixed with OPT_ and uppercased
68 # keyword arguments get prefixed with OPT_ and uppercased
83 env.update((b'OPT_%s' % key.upper(), value)
69 env.update((b'OPT_%s' % key.upper(), value)
84 for key, value in pycompat.byteskwargs(opts).items())
70 for key, value in pycompat.byteskwargs(opts).items())
@@ -29,18 +29,14 b' Test if logtoprocess correctly captures '
29 > [logtoprocess]
29 > [logtoprocess]
30 > command=(echo 'logtoprocess command output:';
30 > command=(echo 'logtoprocess command output:';
31 > echo "\$EVENT";
31 > echo "\$EVENT";
32 > echo "\$MSG1";
32 > echo "\$MSG1") > $TESTTMP/command.log
33 > echo "\$MSG2") > $TESTTMP/command.log
34 > commandfinish=(echo 'logtoprocess commandfinish output:';
33 > commandfinish=(echo 'logtoprocess commandfinish output:';
35 > echo "\$EVENT";
34 > echo "\$EVENT";
36 > echo "\$MSG1";
35 > echo "\$MSG1";
37 > echo "\$MSG2";
38 > echo "\$MSG3";
39 > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log
36 > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log
40 > foo=(echo 'logtoprocess foo output:';
37 > foo=(echo 'logtoprocess foo output:';
41 > echo "\$EVENT";
38 > echo "\$EVENT";
42 > echo "\$MSG1";
39 > echo "\$MSG1") > $TESTTMP/foo.log
43 > echo "\$MSG2") > $TESTTMP/foo.log
44 > EOF
40 > EOF
45
41
46 Running a command triggers both a ui.log('command') and a
42 Running a command triggers both a ui.log('command') and a
@@ -53,16 +49,13 b' Use sort to avoid ordering issues betwee'
53
49
54 command
50 command
55 fooba
51 fooba
56 fooba
57 logtoprocess command output:
52 logtoprocess command output:
58
53
59 #if no-chg
54 #if no-chg
60 $ cat $TESTTMP/commandfinish.log | sort
55 $ cat $TESTTMP/commandfinish.log | sort
61
56
62 0
63 canonical: foobar
57 canonical: foobar
64 commandfinish
58 commandfinish
65 fooba
66 fooba exited 0 after * seconds (glob)
59 fooba exited 0 after * seconds (glob)
67 logtoprocess commandfinish output:
60 logtoprocess commandfinish output:
68 $ cat $TESTTMP/foo.log | sort
61 $ cat $TESTTMP/foo.log | sort
@@ -70,7 +63,6 b' Use sort to avoid ordering issues betwee'
70 a message: spam
63 a message: spam
71 foo
64 foo
72 logtoprocess foo output:
65 logtoprocess foo output:
73 spam
74 #endif
66 #endif
75
67
76 Confirm that logging blocked time catches stdio properly:
68 Confirm that logging blocked time catches stdio properly:
General Comments 0
You need to be logged in to leave comments. Login now