##// END OF EJS Templates
blackbox: send debug message to logger by core ui...
Yuya Nishihara -
r40792:fdc6eb1d default
parent child Browse files
Show More
@@ -52,7 +52,6 b' from mercurial import ('
52 encoding,
52 encoding,
53 pycompat,
53 pycompat,
54 registrar,
54 registrar,
55 ui as uimod,
56 )
55 )
57 from mercurial.utils import (
56 from mercurial.utils import (
58 dateutil,
57 dateutil,
@@ -129,7 +128,6 b' def _openlogfile(ui, vfs):'
129 class blackboxlogger(object):
128 class blackboxlogger(object):
130 def __init__(self, ui):
129 def __init__(self, ui):
131 self._repo = None
130 self._repo = None
132 self._inlog = False
133 self._trackedevents = set(ui.configlist('blackbox', 'track'))
131 self._trackedevents = set(ui.configlist('blackbox', 'track'))
134
132
135 @property
133 @property
@@ -158,10 +156,6 b' class blackboxlogger(object):'
158 _lastlogger._log(ui, event, msg, opts)
156 _lastlogger._log(ui, event, msg, opts)
159
157
160 def _log(self, ui, event, msg, opts):
158 def _log(self, ui, event, msg, opts):
161 if self._inlog:
162 # recursion guard
163 return
164 self._inlog = True
165 default = ui.configdate('devel', 'default-date')
159 default = ui.configdate('devel', 'default-date')
166 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
160 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
167 user = procutil.getuser()
161 user = procutil.getuser()
@@ -189,25 +183,10 b' class blackboxlogger(object):'
189 self._repo = None
183 self._repo = None
190 ui.debug('warning: cannot write to blackbox.log: %s\n' %
184 ui.debug('warning: cannot write to blackbox.log: %s\n' %
191 encoding.strtolocal(err.strerror))
185 encoding.strtolocal(err.strerror))
192 else:
193 self._inlog = False
194
186
195 def setrepo(self, repo):
187 def setrepo(self, repo):
196 self._repo = repo
188 self._repo = repo
197
189
198 def wrapui(ui):
199 class blackboxui(ui.__class__):
200 def debug(self, *msg, **opts):
201 super(blackboxui, self).debug(*msg, **opts)
202 if self.debugflag:
203 self.log('debug', '%s', ''.join(msg))
204
205 ui.__class__ = blackboxui
206 uimod.ui = blackboxui
207
208 def uisetup(ui):
209 wrapui(ui)
210
211 def uipopulate(ui):
190 def uipopulate(ui):
212 ui.setlogger(b'blackbox', blackboxlogger(ui))
191 ui.setlogger(b'blackbox', blackboxlogger(ui))
213
192
@@ -1521,6 +1521,7 b' class ui(object):'
1521 '''
1521 '''
1522 if self.debugflag:
1522 if self.debugflag:
1523 self._writemsg(self._fmsgout, type='debug', *msg, **opts)
1523 self._writemsg(self._fmsgout, type='debug', *msg, **opts)
1524 self.log(b'debug', b'%s', b''.join(msg))
1524
1525
1525 def edit(self, text, user, extra=None, editform=None, pending=None,
1526 def edit(self, text, user, extra=None, editform=None, pending=None,
1526 repopath=None, action=None):
1527 repopath=None, action=None):
@@ -1740,8 +1741,14 b' class ui(object):'
1740 if l.tracked(event)]
1741 if l.tracked(event)]
1741 if not activeloggers:
1742 if not activeloggers:
1742 return
1743 return
1743 for logger in activeloggers:
1744 # guard against recursion from e.g. ui.debug()
1744 logger.log(self, event, msg, opts)
1745 registeredloggers = self._loggers
1746 self._loggers = {}
1747 try:
1748 for logger in activeloggers:
1749 logger.log(self, event, msg, opts)
1750 finally:
1751 self._loggers = registeredloggers
1745
1752
1746 def label(self, msg, label):
1753 def label(self, msg, label):
1747 '''style msg based on supplied label
1754 '''style msg based on supplied label
General Comments 0
You need to be logged in to leave comments. Login now