##// END OF EJS Templates
commandserver: install logger to record server events through canonical API...
Yuya Nishihara -
r40859:82210d88 default
parent child Browse files
Show More
@@ -219,7 +219,7 def _newchgui(srcui, csystem, attachio):
219 219
220 220 return chgui(srcui)
221 221
222 def _loadnewui(srcui, args):
222 def _loadnewui(srcui, args, cdebug):
223 223 from . import dispatch # avoid cycle
224 224
225 225 newui = srcui.__class__.load()
@@ -247,8 +247,10 def _loadnewui(srcui, args):
247 247 path, newlui = dispatch._getlocal(newui, rpath, wd=cwd)
248 248
249 249 extensions.populateui(newui)
250 commandserver.setuplogging(newui, fp=cdebug)
250 251 if newui is not newlui:
251 252 extensions.populateui(newlui)
253 commandserver.setuplogging(newlui, fp=cdebug)
252 254
253 255 return (newui, newlui)
254 256
@@ -423,7 +425,7 class chgcmdserver(commandserver.server)
423 425
424 426 args = self._readlist()
425 427 try:
426 self.ui, lui = _loadnewui(self.ui, args)
428 self.ui, lui = _loadnewui(self.ui, args, self.cdebug)
427 429 except error.ParseError as inst:
428 430 dispatch._formatparse(self.ui.warn, inst)
429 431 self.ui.flush()
@@ -26,8 +26,10 from .i18n import _
26 26 from . import (
27 27 encoding,
28 28 error,
29 loggingutil,
29 30 pycompat,
30 31 util,
32 vfs as vfsmod,
31 33 )
32 34 from .utils import (
33 35 cborutil,
@@ -223,11 +225,18 class server(object):
223 225 self.ui = ui
224 226 self.repo = self.repoui = None
225 227
228 self.cdebug = logfile
226 229 self.cerr = channeledoutput(fout, 'e')
227 230 self.cout = channeledoutput(fout, 'o')
228 231 self.cin = channeledinput(fin, fout, 'I')
229 232 self.cresult = channeledoutput(fout, 'r')
230 233
234 if self.ui.config(b'cmdserver', b'log') == b'-':
235 # switch log stream of server's ui to the 'd' (debug) channel
236 # (don't touch repo.ui as its lifetime is longer than the server)
237 self.ui = self.ui.copy()
238 setuplogging(self.ui, repo=None, fp=self.cdebug)
239
231 240 # TODO: add this to help/config.txt when stabilized
232 241 # ``channel``
233 242 # Use separate channel for structured output. (Command-server only)
@@ -356,17 +365,18 class server(object):
356 365
357 366 return 0
358 367
359 def setuplogging(ui):
368 def setuplogging(ui, repo=None, fp=None):
360 369 """Set up server logging facility
361 370
362 If cmdserver.log is '-', log messages will be sent to the 'd' channel
363 while a client is connected. Otherwise, messages will be written to
364 the stderr of the server process.
371 If cmdserver.log is '-', log messages will be sent to the given fp.
372 It should be the 'd' channel while a client is connected, and otherwise
373 is the stderr of the server process.
365 374 """
366 375 # developer config: cmdserver.log
367 376 logpath = ui.config(b'cmdserver', b'log')
368 377 if not logpath:
369 378 return
379 tracked = {b'cmdserver'}
370 380
371 381 global logfile
372 382 if logpath == b'-':
@@ -374,6 +384,22 def setuplogging(ui):
374 384 else:
375 385 logfile = open(logpath, 'ab')
376 386
387 if logpath == b'-' and fp:
388 logger = loggingutil.fileobjectlogger(fp, tracked)
389 elif logpath == b'-':
390 logger = loggingutil.fileobjectlogger(ui.ferr, tracked)
391 else:
392 logpath = os.path.abspath(logpath)
393 vfs = vfsmod.vfs(os.path.dirname(logpath))
394 logger = loggingutil.filelogger(vfs, os.path.basename(logpath), tracked)
395
396 targetuis = {ui}
397 if repo:
398 targetuis.add(repo.baseui)
399 targetuis.add(repo.ui)
400 for u in targetuis:
401 u.setlogger(b'cmdserver', logger)
402
377 403 class pipeservice(object):
378 404 def __init__(self, ui, repo, opts):
379 405 self.ui = ui
@@ -158,7 +158,7 def _createcmdservice(ui, repo, opts):
158 158 servicefn = _cmdservicemap[mode]
159 159 except KeyError:
160 160 raise error.Abort(_('unknown mode %s') % mode)
161 commandserver.setuplogging(ui)
161 commandserver.setuplogging(ui, repo)
162 162 return servicefn(ui, repo, opts)
163 163
164 164 def _createhgwebservice(ui, repo, opts):
General Comments 0
You need to be logged in to leave comments. Login now