##// 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 b' def _newchgui(srcui, csystem, attachio):'
219
219
220 return chgui(srcui)
220 return chgui(srcui)
221
221
222 def _loadnewui(srcui, args):
222 def _loadnewui(srcui, args, cdebug):
223 from . import dispatch # avoid cycle
223 from . import dispatch # avoid cycle
224
224
225 newui = srcui.__class__.load()
225 newui = srcui.__class__.load()
@@ -247,8 +247,10 b' def _loadnewui(srcui, args):'
247 path, newlui = dispatch._getlocal(newui, rpath, wd=cwd)
247 path, newlui = dispatch._getlocal(newui, rpath, wd=cwd)
248
248
249 extensions.populateui(newui)
249 extensions.populateui(newui)
250 commandserver.setuplogging(newui, fp=cdebug)
250 if newui is not newlui:
251 if newui is not newlui:
251 extensions.populateui(newlui)
252 extensions.populateui(newlui)
253 commandserver.setuplogging(newlui, fp=cdebug)
252
254
253 return (newui, newlui)
255 return (newui, newlui)
254
256
@@ -423,7 +425,7 b' class chgcmdserver(commandserver.server)'
423
425
424 args = self._readlist()
426 args = self._readlist()
425 try:
427 try:
426 self.ui, lui = _loadnewui(self.ui, args)
428 self.ui, lui = _loadnewui(self.ui, args, self.cdebug)
427 except error.ParseError as inst:
429 except error.ParseError as inst:
428 dispatch._formatparse(self.ui.warn, inst)
430 dispatch._formatparse(self.ui.warn, inst)
429 self.ui.flush()
431 self.ui.flush()
@@ -26,8 +26,10 b' from .i18n import _'
26 from . import (
26 from . import (
27 encoding,
27 encoding,
28 error,
28 error,
29 loggingutil,
29 pycompat,
30 pycompat,
30 util,
31 util,
32 vfs as vfsmod,
31 )
33 )
32 from .utils import (
34 from .utils import (
33 cborutil,
35 cborutil,
@@ -223,11 +225,18 b' class server(object):'
223 self.ui = ui
225 self.ui = ui
224 self.repo = self.repoui = None
226 self.repo = self.repoui = None
225
227
228 self.cdebug = logfile
226 self.cerr = channeledoutput(fout, 'e')
229 self.cerr = channeledoutput(fout, 'e')
227 self.cout = channeledoutput(fout, 'o')
230 self.cout = channeledoutput(fout, 'o')
228 self.cin = channeledinput(fin, fout, 'I')
231 self.cin = channeledinput(fin, fout, 'I')
229 self.cresult = channeledoutput(fout, 'r')
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 # TODO: add this to help/config.txt when stabilized
240 # TODO: add this to help/config.txt when stabilized
232 # ``channel``
241 # ``channel``
233 # Use separate channel for structured output. (Command-server only)
242 # Use separate channel for structured output. (Command-server only)
@@ -356,17 +365,18 b' class server(object):'
356
365
357 return 0
366 return 0
358
367
359 def setuplogging(ui):
368 def setuplogging(ui, repo=None, fp=None):
360 """Set up server logging facility
369 """Set up server logging facility
361
370
362 If cmdserver.log is '-', log messages will be sent to the 'd' channel
371 If cmdserver.log is '-', log messages will be sent to the given fp.
363 while a client is connected. Otherwise, messages will be written to
372 It should be the 'd' channel while a client is connected, and otherwise
364 the stderr of the server process.
373 is the stderr of the server process.
365 """
374 """
366 # developer config: cmdserver.log
375 # developer config: cmdserver.log
367 logpath = ui.config(b'cmdserver', b'log')
376 logpath = ui.config(b'cmdserver', b'log')
368 if not logpath:
377 if not logpath:
369 return
378 return
379 tracked = {b'cmdserver'}
370
380
371 global logfile
381 global logfile
372 if logpath == b'-':
382 if logpath == b'-':
@@ -374,6 +384,22 b' def setuplogging(ui):'
374 else:
384 else:
375 logfile = open(logpath, 'ab')
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 class pipeservice(object):
403 class pipeservice(object):
378 def __init__(self, ui, repo, opts):
404 def __init__(self, ui, repo, opts):
379 self.ui = ui
405 self.ui = ui
@@ -158,7 +158,7 b' def _createcmdservice(ui, repo, opts):'
158 servicefn = _cmdservicemap[mode]
158 servicefn = _cmdservicemap[mode]
159 except KeyError:
159 except KeyError:
160 raise error.Abort(_('unknown mode %s') % mode)
160 raise error.Abort(_('unknown mode %s') % mode)
161 commandserver.setuplogging(ui)
161 commandserver.setuplogging(ui, repo)
162 return servicefn(ui, repo, opts)
162 return servicefn(ui, repo, opts)
163
163
164 def _createhgwebservice(ui, repo, opts):
164 def _createhgwebservice(ui, repo, opts):
General Comments 0
You need to be logged in to leave comments. Login now