commandserver: add config knob for various logging options
authorYuya Nishihara <yuya@tcha.org>
Sun, 18 Nov 2018 19:47:04 +0900
changeset 53592 d23fd01cc1156fcb856299e009796066fbde15db
parent 53591 1617aa916d8851a344a870bda273928a11b01541
child 53593 25e9089c7686be81d3500432be008ef08a142487
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
commandserver: add config knob for various logging options The default rotating options are copied from the blackbox extension.
mercurial/commandserver.py
mercurial/configitems.py
tests/test-chg.t
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -355,26 +355,32 @@ def setuplogging(ui, repo=None, fp=None)
     If cmdserver.log is '-', log messages will be sent to the given fp.
     It should be the 'd' channel while a client is connected, and otherwise
     is the stderr of the server process.
     """
     # developer config: cmdserver.log
     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)
     elif logpath == b'-':
         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:
         targetuis.add(repo.baseui)
         targetuis.add(repo.ui)
     for u in targetuis:
         u.setlogger(b'cmdserver', logger)
 
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -168,19 +168,28 @@ coreconfigitem('chgserver', 'idletimeout
     default=3600,
 )
 coreconfigitem('chgserver', 'skiphash',
     default=False,
 )
 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,
 )
 coreconfigitem('color', 'mode',
     default='auto',
 )
 coreconfigitem('color', 'pagermode',
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -1,13 +1,16 @@
 #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
 
   $ filterlog () {
   >   sed -e 's!^[0-9/]* [0-9:]* ([0-9]*)>!YYYY/MM/DD HH:MM:SS (PID)>!' \
   >       -e 's!\(setprocname\|received fds\|setenv\): .*!\1: ...!' \
   >       -e 's!\(confighash\|mtimehash\) = [0-9a-f]*!\1 = ...!g' \
   >       -e 's!\(pid\)=[0-9]*!\1=...!g' \
@@ -214,199 +217,26 @@ shut down servers and restore environmen
 
   $ rm -R chgsock
   $ sleep 2
   $ CHGSOCKNAME=$OLDCHGSOCKNAME
   $ cd ..
 
 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 = ...
   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: ['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: []