Show More
@@ -9,21 +9,21 b'' | |||
|
9 | 9 | This extension lets you specify a shell command per ui.log() event, |
|
10 | 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 | |
|
13 | environment, starting at 1 (so `MSG1`, `MSG2`, etc.). Each keyword argument | |
|
14 | is set as a `OPT_UPPERCASE_KEY` variable (so the key is uppercased, and | |
|
15 | prefixed with `OPT_`). The original event name is passed in the `EVENT` | |
|
16 |
|
|
|
12 | Positional arguments construct a log message, which is passed in the `MSG1` | |
|
13 | environment variables. Each keyword argument is set as a `OPT_UPPERCASE_KEY` | |
|
14 | variable (so the key is uppercased, and prefixed with `OPT_`). The original | |
|
15 | event name is passed in the `EVENT` environment variable, and the process ID | |
|
16 | of mercurial is given in `HGPID`. | |
|
17 | 17 | |
|
18 |
So given a call `ui.log('foo', 'bar', 'baz', spam='eggs'), a script |
|
|
19 |
for the `foo` event can expect an environment with `MSG1=bar |
|
|
20 | `OPT_SPAM=eggs`. | |
|
18 | So given a call `ui.log('foo', 'bar %s\n', 'baz', spam='eggs'), a script | |
|
19 | configured for the `foo` event can expect an environment with `MSG1=bar baz`, | |
|
20 | and `OPT_SPAM=eggs`. | |
|
21 | 21 | |
|
22 | 22 | Scripts are configured in the `[logtoprocess]` section, each key an event name. |
|
23 | 23 | For example:: |
|
24 | 24 | |
|
25 | 25 | [logtoprocess] |
|
26 |
commandexception = echo "$MSG |
|
|
26 | commandexception = echo "$MSG1" > /var/log/mercurial_exceptions.log | |
|
27 | 27 | |
|
28 | 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 | 61 | script = self.config('logtoprocess', event) |
|
62 | 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 | 63 | env = { |
|
76 | 64 | b'EVENT': event, |
|
77 | 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 | 68 | # keyword arguments get prefixed with OPT_ and uppercased |
|
83 | 69 | env.update((b'OPT_%s' % key.upper(), value) |
|
84 | 70 | for key, value in pycompat.byteskwargs(opts).items()) |
@@ -29,18 +29,14 b' Test if logtoprocess correctly captures ' | |||
|
29 | 29 | > [logtoprocess] |
|
30 | 30 | > command=(echo 'logtoprocess command output:'; |
|
31 | 31 | > echo "\$EVENT"; |
|
32 |
> echo "\$MSG1" |
|
|
33 | > echo "\$MSG2") > $TESTTMP/command.log | |
|
32 | > echo "\$MSG1") > $TESTTMP/command.log | |
|
34 | 33 | > commandfinish=(echo 'logtoprocess commandfinish output:'; |
|
35 | 34 | > echo "\$EVENT"; |
|
36 | 35 | > echo "\$MSG1"; |
|
37 | > echo "\$MSG2"; | |
|
38 | > echo "\$MSG3"; | |
|
39 | 36 | > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log |
|
40 | 37 | > foo=(echo 'logtoprocess foo output:'; |
|
41 | 38 | > echo "\$EVENT"; |
|
42 |
> echo "\$MSG1" |
|
|
43 | > echo "\$MSG2") > $TESTTMP/foo.log | |
|
39 | > echo "\$MSG1") > $TESTTMP/foo.log | |
|
44 | 40 | > EOF |
|
45 | 41 | |
|
46 | 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 | 50 | command |
|
55 | 51 | fooba |
|
56 | fooba | |
|
57 | 52 | logtoprocess command output: |
|
58 | 53 | |
|
59 | 54 | #if no-chg |
|
60 | 55 | $ cat $TESTTMP/commandfinish.log | sort |
|
61 | 56 | |
|
62 | 0 | |
|
63 | 57 | canonical: foobar |
|
64 | 58 | commandfinish |
|
65 | fooba | |
|
66 | 59 | fooba exited 0 after * seconds (glob) |
|
67 | 60 | logtoprocess commandfinish output: |
|
68 | 61 | $ cat $TESTTMP/foo.log | sort |
@@ -70,7 +63,6 b' Use sort to avoid ordering issues betwee' | |||
|
70 | 63 | a message: spam |
|
71 | 64 | foo |
|
72 | 65 | logtoprocess foo output: |
|
73 | spam | |
|
74 | 66 | #endif |
|
75 | 67 | |
|
76 | 68 | Confirm that logging blocked time catches stdio properly: |
General Comments 0
You need to be logged in to leave comments.
Login now