Mercurial > hg-stable
diff hgext/blackbox.py @ 40764:55b053af7196
ui: manage logger instances and event filtering by core ui
The setup code in blackbox needs more tweaks since it has lots of black
magics. I'll fix them by follow-up patches.
To be clear, the goal of this series is to provide a proper way for command
server to install its own logger. I need it to debug in-memory repository
cache.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 11 Nov 2018 18:08:33 +0900 |
parents | 85372dc0cca3 |
children | eb5948f29c60 |
line wrap: on
line diff
--- a/hgext/blackbox.py Mon Nov 12 21:10:51 2018 +0900 +++ b/hgext/blackbox.py Sun Nov 11 18:08:33 2018 +0900 @@ -53,7 +53,6 @@ pycompat, registrar, ui as uimod, - util, ) from mercurial.utils import ( dateutil, @@ -147,9 +146,6 @@ def log(self, ui, event, msg, opts): global _lastlogger - if not self.tracked(event): - return - if self._bbvfs: _lastlogger = self elif _lastlogger and _lastlogger._bbvfs: @@ -201,33 +197,20 @@ def wrapui(ui): class blackboxui(ui.__class__): - def __init__(self, src=None): - super(blackboxui, self).__init__(src) - if src and r'_bblogger' in src.__dict__: - self._bblogger = src._bblogger - - # trick to initialize logger after configuration is loaded, which - # can be replaced later with blackboxlogger(ui) in uisetup(), where - # both user and repo configurations should be available. - @util.propertycache - def _bblogger(self): - return blackboxlogger(self) - def debug(self, *msg, **opts): super(blackboxui, self).debug(*msg, **opts) if self.debugflag: self.log('debug', '%s', ''.join(msg)) - def log(self, event, *msg, **opts): - super(blackboxui, self).log(event, *msg, **opts) - self._bblogger.log(self, event, msg, opts) - ui.__class__ = blackboxui uimod.ui = blackboxui def uisetup(ui): wrapui(ui) +def uipopulate(ui): + ui.setlogger(b'blackbox', blackboxlogger(ui)) + def reposetup(ui, repo): # During 'hg pull' a httppeer repo is created to represent the remote repo. # It doesn't have a .hg directory to put a blackbox in, so we don't do @@ -235,7 +218,10 @@ if not repo.local(): return - logger = getattr(ui, '_bblogger', None) + # Since blackbox.log is stored in the repo directory, the logger should be + # instantiated per repository. + logger = blackboxlogger(ui) + ui.setlogger(b'blackbox', logger) if logger: logger.setrepo(repo)