--- a/hgext/logtoprocess.py Sun Nov 11 12:35:38 2018 +0900
+++ b/hgext/logtoprocess.py Sun Nov 11 12:55:58 2018 +0900
@@ -9,21 +9,21 @@
This extension lets you specify a shell command per ui.log() event,
sending all remaining arguments to as environment variables to that command.
-Each positional argument to the method results in a `MSG[N]` key in the
-environment, starting at 1 (so `MSG1`, `MSG2`, etc.). Each keyword argument
-is set as a `OPT_UPPERCASE_KEY` variable (so the key is uppercased, and
-prefixed with `OPT_`). The original event name is passed in the `EVENT`
-environment variable, and the process ID of mercurial is given in `HGPID`.
+Positional arguments construct a log message, which is passed in the `MSG1`
+environment variables. Each keyword argument is set as a `OPT_UPPERCASE_KEY`
+variable (so the key is uppercased, and prefixed with `OPT_`). The original
+event name is passed in the `EVENT` environment variable, and the process ID
+of mercurial is given in `HGPID`.
-So given a call `ui.log('foo', 'bar', 'baz', spam='eggs'), a script configured
-for the `foo` event can expect an environment with `MSG1=bar`, `MSG2=baz`, and
-`OPT_SPAM=eggs`.
+So given a call `ui.log('foo', 'bar %s\n', 'baz', spam='eggs'), a script
+configured for the `foo` event can expect an environment with `MSG1=bar baz`,
+and `OPT_SPAM=eggs`.
Scripts are configured in the `[logtoprocess]` section, each key an event name.
For example::
[logtoprocess]
- commandexception = echo "$MSG2$MSG3" > /var/log/mercurial_exceptions.log
+ commandexception = echo "$MSG1" > /var/log/mercurial_exceptions.log
would log the warning message and traceback of any failed command dispatch.
@@ -60,25 +60,11 @@
"""
script = self.config('logtoprocess', event)
if script:
- if msg:
- # try to format the log message given the remaining
- # arguments
- try:
- # Format the message as blackbox does
- formatted = msg[0] % msg[1:]
- except (TypeError, KeyError):
- # Failed to apply the arguments, ignore
- formatted = msg[0]
- messages = (formatted,) + msg[1:]
- else:
- messages = msg
env = {
b'EVENT': event,
b'HGPID': os.getpid(),
+ b'MSG1': msg[0] % msg[1:],
}
- # positional arguments are listed as MSG[N] keys in the
- # environment
- env.update((b'MSG%d' % i, m) for i, m in enumerate(messages, 1))
# keyword arguments get prefixed with OPT_ and uppercased
env.update((b'OPT_%s' % key.upper(), value)
for key, value in pycompat.byteskwargs(opts).items())