Patchwork [7,of,8] commandserver: add config knob for various logging options

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 4, 2018, 1:24 p.m.
Message ID <05530c3d01119b718a9f.1543929861@mimosa>
Download mbox | patch
Permalink /patch/36954/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 4, 2018, 1:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1542538024 -32400
#      Sun Nov 18 19:47:04 2018 +0900
# Node ID 05530c3d01119b718a9fb8ca4ef60ae9624441cd
# Parent  6dc23c03f0639d051baeb7c4a8889f59b0217025
commandserver: add config knob for various logging options

The default rotating options are copied from the blackbox extension.

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -360,7 +360,8 @@  def setuplogging(ui, repo=None, fp=None)
     logpath = ui.config(b'cmdserver', b'log')
     if not logpath:
         return
-    tracked = {b'chgserver', b'cmdserver'}
+    # developer config: cmdserver.track-log
+    tracked = set(ui.configlist(b'cmdserver', b'track-log'))
 
     if logpath == b'-' and fp:
         logger = loggingutil.fileobjectlogger(fp, tracked)
@@ -368,8 +369,13 @@  def setuplogging(ui, repo=None, fp=None)
         logger = loggingutil.fileobjectlogger(ui.ferr, tracked)
     else:
         logpath = os.path.abspath(util.expandpath(logpath))
+        # developer config: cmdserver.max-log-files
+        maxfiles = ui.configint(b'cmdserver', b'max-log-files')
+        # developer config: cmdserver.max-log-size
+        maxsize = ui.configbytes(b'cmdserver', b'max-log-size')
         vfs = vfsmod.vfs(os.path.dirname(logpath))
-        logger = loggingutil.filelogger(vfs, os.path.basename(logpath), tracked)
+        logger = loggingutil.filelogger(vfs, os.path.basename(logpath), tracked,
+                                        maxfiles=maxfiles, maxsize=maxsize)
 
     targetuis = {ui}
     if repo:
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -173,9 +173,18 @@  coreconfigitem('chgserver', 'skiphash',
 coreconfigitem('cmdserver', 'log',
     default=None,
 )
+coreconfigitem('cmdserver', 'max-log-files',
+    default=7,
+)
+coreconfigitem('cmdserver', 'max-log-size',
+    default='1 MB',
+)
 coreconfigitem('cmdserver', 'message-encodings',
     default=list,
 )
+coreconfigitem('cmdserver', 'track-log',
+    default=lambda: ['chgserver', 'cmdserver'],
+)
 coreconfigitem('color', '.*',
     default=None,
     generic=True,
diff --git a/tests/test-chg.t b/tests/test-chg.t
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -1,8 +1,11 @@ 
 #require chg
 
+  $ mkdir log
   $ cat <<'EOF' >> $HGRCPATH
   > [cmdserver]
-  > log = $TESTTMP/server.log
+  > log = $TESTTMP/log/server.log
+  > max-log-files = 1
+  > max-log-size = 10 kB
   > EOF
   $ cp $HGRCPATH $HGRCPATH.orig
 
@@ -219,157 +222,14 @@  shut down servers and restore environmen
 
 check that server events are recorded:
 
-  $ cat server.log | filterlog
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/foo'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/foo'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/foo'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/editor'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/editor'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['redirect $TESTTMP.chgsock/server-...']
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/editor'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/editor'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['redirect $TESTTMP.chgsock/server-...']
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/editor'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['redirect $TESTTMP.chgsock/server-...']
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['redirect $TESTTMP.chgsock/server-...']
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['redirect $TESTTMP.chgsock/server-...']
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/pager'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['redirect $TESTTMP.chgsock/server-...']
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
+  $ ls log
+  server.log
+  server.log.1
+
+print only the last 10 lines, since we aren't sure how many records are
+preserved:
+
+  $ cat log/server.log.1 log/server.log | tail -10 | filterlog
   YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
   YYYY/MM/DD HH:MM:SS (PID)> validate: []
   YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
@@ -380,33 +240,3 @@  check that server events are recorded:
   YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
   YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
   YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/extreload'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: ['unlink $TESTTMP/extreload/chgsock/server-...', 'reconnect']
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/extreload'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/extreload'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> setprocname: ...
-  YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
-  YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/extreload'
-  YYYY/MM/DD HH:MM:SS (PID)> setumask 18
-  YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
-  YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
-  YYYY/MM/DD HH:MM:SS (PID)> validate: []