comparison mercurial/ui.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 c72a81bc2e82
children fdc6eb1d650d
comparison
equal deleted inserted replaced
40763:c93d046d4300 40764:55b053af7196
233 self._fin = src._fin 233 self._fin = src._fin
234 self._fmsg = src._fmsg 234 self._fmsg = src._fmsg
235 self._fmsgout = src._fmsgout 235 self._fmsgout = src._fmsgout
236 self._fmsgerr = src._fmsgerr 236 self._fmsgerr = src._fmsgerr
237 self._finoutredirected = src._finoutredirected 237 self._finoutredirected = src._finoutredirected
238 self._loggers = src._loggers.copy()
238 self.pageractive = src.pageractive 239 self.pageractive = src.pageractive
239 self._disablepager = src._disablepager 240 self._disablepager = src._disablepager
240 self._tweaked = src._tweaked 241 self._tweaked = src._tweaked
241 242
242 self._tcfg = src._tcfg.copy() 243 self._tcfg = src._tcfg.copy()
261 self._fin = procutil.stdin 262 self._fin = procutil.stdin
262 self._fmsg = None 263 self._fmsg = None
263 self._fmsgout = self.fout # configurable 264 self._fmsgout = self.fout # configurable
264 self._fmsgerr = self.ferr # configurable 265 self._fmsgerr = self.ferr # configurable
265 self._finoutredirected = False 266 self._finoutredirected = False
267 self._loggers = {}
266 self.pageractive = False 268 self.pageractive = False
267 self._disablepager = False 269 self._disablepager = False
268 self._tweaked = False 270 self._tweaked = False
269 271
270 # shared read-only environment 272 # shared read-only environment
1707 1709
1708 def makeprogress(self, topic, unit="", total=None): 1710 def makeprogress(self, topic, unit="", total=None):
1709 '''exists only so low-level modules won't need to import scmutil''' 1711 '''exists only so low-level modules won't need to import scmutil'''
1710 return scmutil.progress(self, topic, unit, total) 1712 return scmutil.progress(self, topic, unit, total)
1711 1713
1714 def getlogger(self, name):
1715 """Returns a logger of the given name; or None if not registered"""
1716 return self._loggers.get(name)
1717
1718 def setlogger(self, name, logger):
1719 """Install logger which can be identified later by the given name
1720
1721 More than one loggers can be registered. Use extension or module
1722 name to uniquely identify the logger instance.
1723 """
1724 self._loggers[name] = logger
1725
1712 def log(self, event, *msg, **opts): 1726 def log(self, event, *msg, **opts):
1713 '''hook for logging facility extensions 1727 '''hook for logging facility extensions
1714 1728
1715 event should be a readily-identifiable subsystem, which will 1729 event should be a readily-identifiable subsystem, which will
1716 allow filtering. 1730 allow filtering.
1718 *msg should be a newline-terminated format string to log, and 1732 *msg should be a newline-terminated format string to log, and
1719 then any values to %-format into that format string. 1733 then any values to %-format into that format string.
1720 1734
1721 **opts currently has no defined meanings. 1735 **opts currently has no defined meanings.
1722 ''' 1736 '''
1737 if not self._loggers:
1738 return
1739 activeloggers = [l for l in self._loggers.itervalues()
1740 if l.tracked(event)]
1741 if not activeloggers:
1742 return
1743 for logger in activeloggers:
1744 logger.log(self, event, msg, opts)
1723 1745
1724 def label(self, msg, label): 1746 def label(self, msg, label):
1725 '''style msg based on supplied label 1747 '''style msg based on supplied label
1726 1748
1727 If some color mode is enabled, this will add the necessary control 1749 If some color mode is enabled, this will add the necessary control