Show More
@@ -53,7 +53,6 from mercurial import ( | |||
|
53 | 53 | pycompat, |
|
54 | 54 | registrar, |
|
55 | 55 | ui as uimod, |
|
56 | util, | |
|
57 | 56 | ) |
|
58 | 57 | from mercurial.utils import ( |
|
59 | 58 | dateutil, |
@@ -147,9 +146,6 class blackboxlogger(object): | |||
|
147 | 146 | |
|
148 | 147 | def log(self, ui, event, msg, opts): |
|
149 | 148 | global _lastlogger |
|
150 | if not self.tracked(event): | |
|
151 | return | |
|
152 | ||
|
153 | 149 | if self._bbvfs: |
|
154 | 150 | _lastlogger = self |
|
155 | 151 | elif _lastlogger and _lastlogger._bbvfs: |
@@ -201,33 +197,20 class blackboxlogger(object): | |||
|
201 | 197 | |
|
202 | 198 | def wrapui(ui): |
|
203 | 199 | class blackboxui(ui.__class__): |
|
204 | def __init__(self, src=None): | |
|
205 | super(blackboxui, self).__init__(src) | |
|
206 | if src and r'_bblogger' in src.__dict__: | |
|
207 | self._bblogger = src._bblogger | |
|
208 | ||
|
209 | # trick to initialize logger after configuration is loaded, which | |
|
210 | # can be replaced later with blackboxlogger(ui) in uisetup(), where | |
|
211 | # both user and repo configurations should be available. | |
|
212 | @util.propertycache | |
|
213 | def _bblogger(self): | |
|
214 | return blackboxlogger(self) | |
|
215 | ||
|
216 | 200 | def debug(self, *msg, **opts): |
|
217 | 201 | super(blackboxui, self).debug(*msg, **opts) |
|
218 | 202 | if self.debugflag: |
|
219 | 203 | self.log('debug', '%s', ''.join(msg)) |
|
220 | 204 | |
|
221 | def log(self, event, *msg, **opts): | |
|
222 | super(blackboxui, self).log(event, *msg, **opts) | |
|
223 | self._bblogger.log(self, event, msg, opts) | |
|
224 | ||
|
225 | 205 | ui.__class__ = blackboxui |
|
226 | 206 | uimod.ui = blackboxui |
|
227 | 207 | |
|
228 | 208 | def uisetup(ui): |
|
229 | 209 | wrapui(ui) |
|
230 | 210 | |
|
211 | def uipopulate(ui): | |
|
212 | ui.setlogger(b'blackbox', blackboxlogger(ui)) | |
|
213 | ||
|
231 | 214 | def reposetup(ui, repo): |
|
232 | 215 | # During 'hg pull' a httppeer repo is created to represent the remote repo. |
|
233 | 216 | # It doesn't have a .hg directory to put a blackbox in, so we don't do |
@@ -235,7 +218,10 def reposetup(ui, repo): | |||
|
235 | 218 | if not repo.local(): |
|
236 | 219 | return |
|
237 | 220 | |
|
238 | logger = getattr(ui, '_bblogger', None) | |
|
221 | # Since blackbox.log is stored in the repo directory, the logger should be | |
|
222 | # instantiated per repository. | |
|
223 | logger = blackboxlogger(ui) | |
|
224 | ui.setlogger(b'blackbox', logger) | |
|
239 | 225 | if logger: |
|
240 | 226 | logger.setrepo(repo) |
|
241 | 227 |
@@ -38,7 +38,6 import os | |||
|
38 | 38 | |
|
39 | 39 | from mercurial import ( |
|
40 | 40 | pycompat, |
|
41 | util, | |
|
42 | 41 | ) |
|
43 | 42 | from mercurial.utils import ( |
|
44 | 43 | procutil, |
@@ -63,9 +62,7 class processlogger(object): | |||
|
63 | 62 | return bool(self._scripts.get(event)) |
|
64 | 63 | |
|
65 | 64 | def log(self, ui, event, msg, opts): |
|
66 |
script = self._scripts |
|
|
67 | if not script: | |
|
68 | return | |
|
65 | script = self._scripts[event] | |
|
69 | 66 | env = { |
|
70 | 67 | b'EVENT': event, |
|
71 | 68 | b'HGPID': os.getpid(), |
@@ -77,24 +74,5 class processlogger(object): | |||
|
77 | 74 | fullenv = procutil.shellenviron(env) |
|
78 | 75 | procutil.runbgcommand(script, fullenv, shell=True) |
|
79 | 76 | |
|
80 |
def ui |
|
|
81 | ||
|
82 | class logtoprocessui(ui.__class__): | |
|
83 | def __init__(self, src=None): | |
|
84 | super(logtoprocessui, self).__init__(src) | |
|
85 | if src and r'_ltplogger' in src.__dict__: | |
|
86 | self._ltplogger = src._ltplogger | |
|
87 | ||
|
88 | # trick to initialize logger after configuration is loaded, which | |
|
89 | # can be replaced later with processlogger(ui) in uisetup(), where | |
|
90 | # both user and repo configurations should be available. | |
|
91 | @util.propertycache | |
|
92 | def _ltplogger(self): | |
|
93 | return processlogger(self) | |
|
94 | ||
|
95 | def log(self, event, *msg, **opts): | |
|
96 | self._ltplogger.log(self, event, msg, opts) | |
|
97 | return super(logtoprocessui, self).log(event, *msg, **opts) | |
|
98 | ||
|
99 | # Replace the class for this instance and all clones created from it: | |
|
100 | ui.__class__ = logtoprocessui | |
|
77 | def uipopulate(ui): | |
|
78 | ui.setlogger(b'logtoprocess', processlogger(ui)) |
@@ -235,6 +235,7 class ui(object): | |||
|
235 | 235 | self._fmsgout = src._fmsgout |
|
236 | 236 | self._fmsgerr = src._fmsgerr |
|
237 | 237 | self._finoutredirected = src._finoutredirected |
|
238 | self._loggers = src._loggers.copy() | |
|
238 | 239 | self.pageractive = src.pageractive |
|
239 | 240 | self._disablepager = src._disablepager |
|
240 | 241 | self._tweaked = src._tweaked |
@@ -263,6 +264,7 class ui(object): | |||
|
263 | 264 | self._fmsgout = self.fout # configurable |
|
264 | 265 | self._fmsgerr = self.ferr # configurable |
|
265 | 266 | self._finoutredirected = False |
|
267 | self._loggers = {} | |
|
266 | 268 | self.pageractive = False |
|
267 | 269 | self._disablepager = False |
|
268 | 270 | self._tweaked = False |
@@ -1709,6 +1711,18 class ui(object): | |||
|
1709 | 1711 | '''exists only so low-level modules won't need to import scmutil''' |
|
1710 | 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 | 1726 | def log(self, event, *msg, **opts): |
|
1713 | 1727 | '''hook for logging facility extensions |
|
1714 | 1728 | |
@@ -1720,6 +1734,14 class ui(object): | |||
|
1720 | 1734 | |
|
1721 | 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 | 1746 | def label(self, msg, label): |
|
1725 | 1747 | '''style msg based on supplied label |
General Comments 0
You need to be logged in to leave comments.
Login now