Show More
@@ -53,7 +53,6 from mercurial import ( | |||||
53 | pycompat, |
|
53 | pycompat, | |
54 | registrar, |
|
54 | registrar, | |
55 | ui as uimod, |
|
55 | ui as uimod, | |
56 | util, |
|
|||
57 | ) |
|
56 | ) | |
58 | from mercurial.utils import ( |
|
57 | from mercurial.utils import ( | |
59 | dateutil, |
|
58 | dateutil, | |
@@ -147,9 +146,6 class blackboxlogger(object): | |||||
147 |
|
146 | |||
148 | def log(self, ui, event, msg, opts): |
|
147 | def log(self, ui, event, msg, opts): | |
149 | global _lastlogger |
|
148 | global _lastlogger | |
150 | if not self.tracked(event): |
|
|||
151 | return |
|
|||
152 |
|
||||
153 | if self._bbvfs: |
|
149 | if self._bbvfs: | |
154 | _lastlogger = self |
|
150 | _lastlogger = self | |
155 | elif _lastlogger and _lastlogger._bbvfs: |
|
151 | elif _lastlogger and _lastlogger._bbvfs: | |
@@ -201,33 +197,20 class blackboxlogger(object): | |||||
201 |
|
197 | |||
202 | def wrapui(ui): |
|
198 | def wrapui(ui): | |
203 | class blackboxui(ui.__class__): |
|
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 | def debug(self, *msg, **opts): |
|
200 | def debug(self, *msg, **opts): | |
217 | super(blackboxui, self).debug(*msg, **opts) |
|
201 | super(blackboxui, self).debug(*msg, **opts) | |
218 | if self.debugflag: |
|
202 | if self.debugflag: | |
219 | self.log('debug', '%s', ''.join(msg)) |
|
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 | ui.__class__ = blackboxui |
|
205 | ui.__class__ = blackboxui | |
226 | uimod.ui = blackboxui |
|
206 | uimod.ui = blackboxui | |
227 |
|
207 | |||
228 | def uisetup(ui): |
|
208 | def uisetup(ui): | |
229 | wrapui(ui) |
|
209 | wrapui(ui) | |
230 |
|
210 | |||
|
211 | def uipopulate(ui): | |||
|
212 | ui.setlogger(b'blackbox', blackboxlogger(ui)) | |||
|
213 | ||||
231 | def reposetup(ui, repo): |
|
214 | def reposetup(ui, repo): | |
232 | # During 'hg pull' a httppeer repo is created to represent the remote repo. |
|
215 | # During 'hg pull' a httppeer repo is created to represent the remote repo. | |
233 | # It doesn't have a .hg directory to put a blackbox in, so we don't do |
|
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 | if not repo.local(): |
|
218 | if not repo.local(): | |
236 | return |
|
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 | if logger: |
|
225 | if logger: | |
240 | logger.setrepo(repo) |
|
226 | logger.setrepo(repo) | |
241 |
|
227 |
@@ -38,7 +38,6 import os | |||||
38 |
|
38 | |||
39 | from mercurial import ( |
|
39 | from mercurial import ( | |
40 | pycompat, |
|
40 | pycompat, | |
41 | util, |
|
|||
42 | ) |
|
41 | ) | |
43 | from mercurial.utils import ( |
|
42 | from mercurial.utils import ( | |
44 | procutil, |
|
43 | procutil, | |
@@ -63,9 +62,7 class processlogger(object): | |||||
63 | return bool(self._scripts.get(event)) |
|
62 | return bool(self._scripts.get(event)) | |
64 |
|
63 | |||
65 | def log(self, ui, event, msg, opts): |
|
64 | def log(self, ui, event, msg, opts): | |
66 |
script = self._scripts |
|
65 | script = self._scripts[event] | |
67 | if not script: |
|
|||
68 | return |
|
|||
69 | env = { |
|
66 | env = { | |
70 | b'EVENT': event, |
|
67 | b'EVENT': event, | |
71 | b'HGPID': os.getpid(), |
|
68 | b'HGPID': os.getpid(), | |
@@ -77,24 +74,5 class processlogger(object): | |||||
77 | fullenv = procutil.shellenviron(env) |
|
74 | fullenv = procutil.shellenviron(env) | |
78 | procutil.runbgcommand(script, fullenv, shell=True) |
|
75 | procutil.runbgcommand(script, fullenv, shell=True) | |
79 |
|
76 | |||
80 |
def ui |
|
77 | def uipopulate(ui): | |
81 |
|
78 | ui.setlogger(b'logtoprocess', processlogger(ui)) | ||
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 |
|
@@ -235,6 +235,7 class ui(object): | |||||
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 | |
@@ -263,6 +264,7 class ui(object): | |||||
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 | |
@@ -1709,6 +1711,18 class ui(object): | |||||
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 | |||
@@ -1720,6 +1734,14 class ui(object): | |||||
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 |
General Comments 0
You need to be logged in to leave comments.
Login now