Patchwork blackbox: add configitem for format of log timestamps

login
register
mail settings
Submitter Matthew DeVore
Date Oct. 17, 2018, 11:34 p.m.
Message ID <alpine.DEB.2.21.1810171626580.166761@matvore-linux.svl.corp.google.com>
Download mbox | patch
Permalink /patch/36147/
State Accepted
Headers show

Comments

Matthew DeVore - Oct. 17, 2018, 11:34 p.m.
# HG changeset patch
# User Matt DeVore <matvore@google.com>
# Date 1539816481 25200
#      Wed Oct 17 15:48:01 2018 -0700
# Node ID b42c2264048f8859c8966577a1929aa80132ffa5
# Parent  5644f7c8982e805e53f56fcbfe0322e9de58a934
blackbox: add configitem for format of log timestamps

Sometimes blackbox logs are used to report performance problems, but the
timestamps are only at second granularity, so often the timings have to
stated separately by the reporter. This is inconvenient and error-prone,
so I would like to include %f in the date format. This patch makes that
possible.
Yuya Nishihara - Oct. 23, 2018, 11:34 a.m.
On Wed, 17 Oct 2018 16:34:53 -0700 (PDT), Matthew DeVore wrote:
> # HG changeset patch
> # User Matt DeVore <matvore@google.com>
> # Date 1539816481 25200
> #      Wed Oct 17 15:48:01 2018 -0700
> # Node ID b42c2264048f8859c8966577a1929aa80132ffa5
> # Parent  5644f7c8982e805e53f56fcbfe0322e9de58a934
> blackbox: add configitem for format of log timestamps

Looks good, but couldn't apply. Can you rebase onto the current tip?

Patch

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -33,6 +33,11 @@  Examples::
    # rotate up to N log files when the current one gets too big
    maxfiles = 3

+  [blackbox]
+  # Include nanoseconds in log entries with %f (see Python function
+  # datetime.datetime.strftime)
+  date-format = '%Y-%m-%d @ %H:%M:%S.%f'
+
  """

  from __future__ import absolute_import
@@ -82,6 +87,9 @@  configitem('blackbox', 'maxfiles',
  configitem('blackbox', 'track',
      default=lambda: ['*'],
  )
+configitem('blackbox', 'date-format',
+    default='%Y/%m/%d %H:%M:%S',
+)

  lastui = None

@@ -169,7 +177,9 @@  def wrapui(ui):
                  return
              ui._bbinlog = True
              default = self.configdate('devel', 'default-date')
-            date = dateutil.datestr(default, '%Y/%m/%d %H:%M:%S')
+            format = ui.config('blackbox', 'date-format')
+            date = dateutil.datestr(default,
+                                    ui.config('blackbox', 'date-format'))
              user = procutil.getuser()
              pid = '%d' % procutil.getpid()
              formattedmsg = msg[0] % msg[1:]
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -82,6 +82,16 @@  recursive aliases work correctly
    1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> so-confusing exited 0 after * seconds (glob)
    1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox

+custom date format
+  $ rm ./.hg/blackbox.log
+  $ hg --config blackbox.date-format='%Y-%m-%d @ %H:%M:%S' \
+  >    --config devel.default-date='1334347993 0' --traceback status
+  A a
+  $ hg blackbox
+  2012-04-13 @ 20:13:13 bob @0000000000000000000000000000000000000000 (5000)> --config 'blackbox.date-format=%Y-%m-%d @ %H:%M:%S' --config 'devel.default-date=1334347993 0' --traceback status
+  2012-04-13 @ 20:13:13 bob @0000000000000000000000000000000000000000 (5000)> --config 'blackbox.date-format=%Y-%m-%d @ %H:%M:%S' --config 'devel.default-date=1334347993 0' --traceback status exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox
+
  incoming change tracking

  create two heads to verify that we only see one change in the log later