Patchwork D8640: ui: add option to timestamp status and diagnostic messages

login
register
mail settings
Submitter phabricator
Date June 18, 2020, 1:14 p.m.
Message ID <differential-rev-PHID-DREV-se3siveqf5hd666f5xk6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46528/
State Superseded
Headers show

Comments

phabricator - June 18, 2020, 1:14 p.m.
joerg.sonnenberger created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D8640

AFFECTED FILES
  mercurial/configitems.py
  mercurial/ui.py
  tests/test-pull.t

CHANGE DETAILS




To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-pull.t b/tests/test-pull.t
--- a/tests/test-pull.t
+++ b/tests/test-pull.t
@@ -142,9 +142,9 @@ 
   pulling from ssh://fakehost%7Ctouch%24%7BIFS%7Downed/path
   abort: no suitable response from remote hg!
   [255]
-  $ hg pull 'ssh://fakehost%7Ctouch%20owned/path'
-  pulling from ssh://fakehost%7Ctouch%20owned/path
-  abort: no suitable response from remote hg!
+  $ hg --config ui.timestamp=true pull 'ssh://fakehost%7Ctouch%20owned/path'
+  \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] pulling from ssh://fakehost%7Ctouch%20owned/path (re)
+  \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] abort: no suitable response from remote hg! (re)
   [255]
 
   $ [ ! -f owned ] || echo 'you got owned'
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -9,6 +9,7 @@ 
 
 import collections
 import contextlib
+import datetime
 import errno
 import getpass
 import inspect
@@ -242,6 +243,7 @@ 
         self._terminfoparams = {}
         self._styles = {}
         self._uninterruptible = False
+        self.showtimestamp = False
 
         if src:
             self._fout = src._fout
@@ -561,6 +563,7 @@ 
             self._reportuntrusted = self.debugflag or self.configbool(
                 b"ui", b"report_untrusted"
             )
+            self.showtimestamp = self.configbool(b'ui', b'timestamp')
             self.tracebackflag = self.configbool(b'ui', b'traceback')
             self.logblockedtimes = self.configbool(b'ui', b'logblockedtimes')
 
@@ -1217,7 +1220,12 @@ 
             ) * 1000
 
     def _writemsg(self, dest, *args, **opts):
+        timestamp = opts.pop('timestamp', False)
+        if timestamp:
+            args = (b'[%s] ' % bytes(datetime.datetime.now().isoformat(), 'ASCII'),) + args
         _writemsgwith(self._write, dest, *args, **opts)
+        if timestamp:
+            dest.flush()
 
     def _writemsgnobuf(self, dest, *args, **opts):
         _writemsgwith(self._writenobuf, dest, *args, **opts)
@@ -1726,21 +1734,21 @@ 
         This adds an output label of "ui.status".
         '''
         if not self.quiet:
-            self._writemsg(self._fmsgout, type=b'status', *msg, **opts)
+            self._writemsg(self._fmsgout, type=b'status', timestamp=self.showtimestamp, *msg, **opts)
 
     def warn(self, *msg, **opts):
         '''write warning message to output (stderr)
 
         This adds an output label of "ui.warning".
         '''
-        self._writemsg(self._fmsgerr, type=b'warning', *msg, **opts)
+        self._writemsg(self._fmsgerr, type=b'warning', timestamp=self.showtimestamp, *msg, **opts)
 
     def error(self, *msg, **opts):
         '''write error message to output (stderr)
 
         This adds an output label of "ui.error".
         '''
-        self._writemsg(self._fmsgerr, type=b'error', *msg, **opts)
+        self._writemsg(self._fmsgerr, type=b'error', timestamp=self.showtimestamp, *msg, **opts)
 
     def note(self, *msg, **opts):
         '''write note to output (if ui.verbose is True)
@@ -1748,7 +1756,8 @@ 
         This adds an output label of "ui.note".
         '''
         if self.verbose:
-            self._writemsg(self._fmsgout, type=b'note', *msg, **opts)
+            self._writemsg(self._fmsgout, type=b'note', timestamp=self.showtimestamp, *msg, **opts)
+            self._fmsgout.flush()
 
     def debug(self, *msg, **opts):
         '''write debug message to output (if ui.debugflag is True)
@@ -1756,7 +1765,8 @@ 
         This adds an output label of "ui.debug".
         '''
         if self.debugflag:
-            self._writemsg(self._fmsgout, type=b'debug', *msg, **opts)
+            self._writemsg(self._fmsgout, type=b'debug', timestamp=self.showtimestamp, *msg, **opts)
+            self._fmsgout.flush()
             self.log(b'debug', b'%s', b''.join(msg))
 
     # Aliases to defeat check-code.
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1391,6 +1391,9 @@ 
     b'ui', b'timeout.warn', default=0,
 )
 coreconfigitem(
+    b'ui', b'timestamp', default=False,
+)
+coreconfigitem(
     b'ui', b'traceback', default=False,
 )
 coreconfigitem(