Mercurial > public > mercurial-scm > hg
comparison mercurial/commandserver.py @ 40823:368ecbf734af
commandserver: enable logging when server process started
This allows us to keep track of server events before client connects to
the server.
Tests will be added later. Currently there's no log() call to check if
things are working well.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 10 Nov 2018 18:19:34 +0900 |
parents | cb372d09d30a |
children | 82210d88d814 |
comparison
equal
deleted
inserted
replaced
40822:6a75363f834a | 40823:368ecbf734af |
---|---|
206 based stream to fout. | 206 based stream to fout. |
207 """ | 207 """ |
208 def __init__(self, ui, repo, fin, fout): | 208 def __init__(self, ui, repo, fin, fout): |
209 self.cwd = encoding.getcwd() | 209 self.cwd = encoding.getcwd() |
210 | 210 |
211 # developer config: cmdserver.log | 211 if ui.config("cmdserver", "log") == '-': |
212 logpath = ui.config("cmdserver", "log") | |
213 if logpath: | |
214 global logfile | 212 global logfile |
215 if logpath == '-': | 213 # switch log stream to the 'd' (debug) channel |
216 # write log on a special 'd' (debug) channel | 214 logfile = channeledoutput(fout, 'd') |
217 logfile = channeledoutput(fout, 'd') | |
218 else: | |
219 logfile = open(logpath, 'a') | |
220 | 215 |
221 if repo: | 216 if repo: |
222 # the ui here is really the repo ui so take its baseui so we don't | 217 # the ui here is really the repo ui so take its baseui so we don't |
223 # end up with its local configuration | 218 # end up with its local configuration |
224 self.ui = repo.baseui | 219 self.ui = repo.baseui |
358 # we'll get here if the client disconnected while we were reading | 353 # we'll get here if the client disconnected while we were reading |
359 # its request | 354 # its request |
360 return 1 | 355 return 1 |
361 | 356 |
362 return 0 | 357 return 0 |
358 | |
359 def setuplogging(ui): | |
360 """Set up server logging facility | |
361 | |
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. | |
365 """ | |
366 # developer config: cmdserver.log | |
367 logpath = ui.config(b'cmdserver', b'log') | |
368 if not logpath: | |
369 return | |
370 | |
371 global logfile | |
372 if logpath == b'-': | |
373 logfile = ui.ferr | |
374 else: | |
375 logfile = open(logpath, 'ab') | |
363 | 376 |
364 class pipeservice(object): | 377 class pipeservice(object): |
365 def __init__(self, ui, repo, opts): | 378 def __init__(self, ui, repo, opts): |
366 self.ui = ui | 379 self.ui = ui |
367 self.repo = repo | 380 self.repo = repo |