comparison 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
comparison
equal deleted inserted replaced
40824:82210d88d814 40825:eaabcb689747
34 from .utils import ( 34 from .utils import (
35 cborutil, 35 cborutil,
36 procutil, 36 procutil,
37 ) 37 )
38 38
39 logfile = None
40
41 def log(*args):
42 if not logfile:
43 return
44
45 for a in args:
46 logfile.write(str(a))
47
48 logfile.flush()
49
50 class channeledoutput(object): 39 class channeledoutput(object):
51 """ 40 """
52 Write data to out in the following format: 41 Write data to out in the following format:
53 42
54 data length (unsigned int), 43 data length (unsigned int),
208 based stream to fout. 197 based stream to fout.
209 """ 198 """
210 def __init__(self, ui, repo, fin, fout): 199 def __init__(self, ui, repo, fin, fout):
211 self.cwd = encoding.getcwd() 200 self.cwd = encoding.getcwd()
212 201
213 if ui.config("cmdserver", "log") == '-':
214 global logfile
215 # switch log stream to the 'd' (debug) channel
216 logfile = channeledoutput(fout, 'd')
217
218 if repo: 202 if repo:
219 # the ui here is really the repo ui so take its baseui so we don't 203 # the ui here is really the repo ui so take its baseui so we don't
220 # end up with its local configuration 204 # end up with its local configuration
221 self.ui = repo.baseui 205 self.ui = repo.baseui
222 self.repo = repo 206 self.repo = repo
223 self.repoui = repo.ui 207 self.repoui = repo.ui
224 else: 208 else:
225 self.ui = ui 209 self.ui = ui
226 self.repo = self.repoui = None 210 self.repo = self.repoui = None
227 211
228 self.cdebug = logfile 212 self.cdebug = channeledoutput(fout, 'd')
229 self.cerr = channeledoutput(fout, 'e') 213 self.cerr = channeledoutput(fout, 'e')
230 self.cout = channeledoutput(fout, 'o') 214 self.cout = channeledoutput(fout, 'o')
231 self.cin = channeledinput(fin, fout, 'I') 215 self.cin = channeledinput(fin, fout, 'I')
232 self.cresult = channeledoutput(fout, 'r') 216 self.cresult = channeledoutput(fout, 'r')
233 217
374 """ 358 """
375 # developer config: cmdserver.log 359 # developer config: cmdserver.log
376 logpath = ui.config(b'cmdserver', b'log') 360 logpath = ui.config(b'cmdserver', b'log')
377 if not logpath: 361 if not logpath:
378 return 362 return
379 tracked = {b'cmdserver'} 363 tracked = {b'chgserver', b'cmdserver'}
380
381 global logfile
382 if logpath == b'-':
383 logfile = ui.ferr
384 else:
385 logfile = open(logpath, 'ab')
386 364
387 if logpath == b'-' and fp: 365 if logpath == b'-' and fp:
388 logger = loggingutil.fileobjectlogger(fp, tracked) 366 logger = loggingutil.fileobjectlogger(fp, tracked)
389 elif logpath == b'-': 367 elif logpath == b'-':
390 logger = loggingutil.fileobjectlogger(ui.ferr, tracked) 368 logger = loggingutil.fileobjectlogger(ui.ferr, tracked)