commandserver: add config knob for various logging options
authorYuya Nishihara <yuya@tcha.org>
Sun, 18 Nov 2018 19:47:04 +0900
changeset 40827 d23fd01cc115
parent 40826 1617aa916d88
child 40828 25e9089c7686
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	Sat Nov 10 19:27:47 2018 +0900
+++ b/mercurial/commandserver.py	Sun Nov 18 19:47:04 2018 +0900
@@ -360,7 +360,8 @@
     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 @@
         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:
--- a/mercurial/configitems.py	Sat Nov 10 19:27:47 2018 +0900
+++ b/mercurial/configitems.py	Sun Nov 18 19:47:04 2018 +0900
@@ -173,9 +173,18 @@
 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,
--- a/tests/test-chg.t	Sat Nov 10 19:27:47 2018 +0900
+++ b/tests/test-chg.t	Sun Nov 18 19:47:04 2018 +0900
@@ -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 @@
 
 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 @@
   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: []