diff mercurial/commandserver.py @ 40825:eaabcb689747

commandserver: switch logging facility to ui.log() interface The "pager subcommand" message is removed since ui isn't accessible there. I think that's okay as cmdtable[cmd]() will call attachio() and some debug message will be printed.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 10 Nov 2018 19:09:37 +0900
parents 82210d88d814
children 1617aa916d88
line wrap: on
line diff
--- a/mercurial/commandserver.py	Sat Nov 10 19:00:17 2018 +0900
+++ b/mercurial/commandserver.py	Sat Nov 10 19:09:37 2018 +0900
@@ -36,17 +36,6 @@
     procutil,
 )
 
-logfile = None
-
-def log(*args):
-    if not logfile:
-        return
-
-    for a in args:
-        logfile.write(str(a))
-
-    logfile.flush()
-
 class channeledoutput(object):
     """
     Write data to out in the following format:
@@ -210,11 +199,6 @@
     def __init__(self, ui, repo, fin, fout):
         self.cwd = encoding.getcwd()
 
-        if ui.config("cmdserver", "log") == '-':
-            global logfile
-            # switch log stream to the 'd' (debug) channel
-            logfile = channeledoutput(fout, 'd')
-
         if repo:
             # the ui here is really the repo ui so take its baseui so we don't
             # end up with its local configuration
@@ -225,7 +209,7 @@
             self.ui = ui
             self.repo = self.repoui = None
 
-        self.cdebug = logfile
+        self.cdebug = channeledoutput(fout, 'd')
         self.cerr = channeledoutput(fout, 'e')
         self.cout = channeledoutput(fout, 'o')
         self.cin = channeledinput(fin, fout, 'I')
@@ -376,13 +360,7 @@
     logpath = ui.config(b'cmdserver', b'log')
     if not logpath:
         return
-    tracked = {b'cmdserver'}
-
-    global logfile
-    if logpath == b'-':
-        logfile = ui.ferr
-    else:
-        logfile = open(logpath, 'ab')
+    tracked = {b'chgserver', b'cmdserver'}
 
     if logpath == b'-' and fp:
         logger = loggingutil.fileobjectlogger(fp, tracked)