Patchwork [3,of,7] ui: pass in formatted message to logger.log()

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 27, 2018, 12:57 p.m.
Message ID <f504187cc42508837296.1543323460@mimosa>
Download mbox | patch
Permalink /patch/36811/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 27, 2018, 12:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541932533 -32400
#      Sun Nov 11 19:35:33 2018 +0900
# Node ID f504187cc42508837296ba92c2261d6879fcacf1
# Parent  29e1cd661c3c67c2099af4dd21631bee0df172ed
ui: pass in formatted message to logger.log()

This makes sure that all logger instances will handle the message arguments
properly.

Patch

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -160,7 +160,6 @@  class blackboxlogger(object):
         date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
         user = procutil.getuser()
         pid = '%d' % procutil.getpid()
-        formattedmsg = msg[0] % msg[1:]
         rev = '(unknown)'
         changed = ''
         ctx = self._repo[None]
@@ -175,7 +174,7 @@  class blackboxlogger(object):
             src = ''
         try:
             fmt = '%s %s @%s%s (%s)%s> %s'
-            args = (date, user, rev, changed, pid, src, formattedmsg)
+            args = (date, user, rev, changed, pid, src, msg)
             with _openlogfile(ui, self._bbvfs) as fp:
                 fp.write(fmt % args)
         except (IOError, OSError) as err:
diff --git a/hgext/logtoprocess.py b/hgext/logtoprocess.py
--- a/hgext/logtoprocess.py
+++ b/hgext/logtoprocess.py
@@ -66,7 +66,7 @@  class processlogger(object):
         env = {
             b'EVENT': event,
             b'HGPID': os.getpid(),
-            b'MSG1': msg[0] % msg[1:],
+            b'MSG1': msg,
         }
         # keyword arguments get prefixed with OPT_ and uppercased
         env.update((b'OPT_%s' % key.upper(), value)
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1724,14 +1724,14 @@  class ui(object):
         """
         self._loggers[name] = logger
 
-    def log(self, event, *msg, **opts):
+    def log(self, event, msgfmt, *msgargs, **opts):
         '''hook for logging facility extensions
 
         event should be a readily-identifiable subsystem, which will
         allow filtering.
 
-        *msg should be a newline-terminated format string to log, and
-        then any values to %-format into that format string.
+        msgfmt should be a newline-terminated format string to log, and
+        *msgargs are %-formatted into it.
 
         **opts currently has no defined meanings.
         '''
@@ -1741,6 +1741,7 @@  class ui(object):
                          if l.tracked(event)]
         if not activeloggers:
             return
+        msg = msgfmt % msgargs
         # guard against recursion from e.g. ui.debug()
         registeredloggers = self._loggers
         self._loggers = {}