##// END OF EJS Templates
blackbox: extract global last logger to proxylogger class...
Yuya Nishihara -
r40795:37d6ee46 default
parent child Browse files
Show More
@@ -89,8 +89,6 b" configitem('blackbox', 'date-format',"
89 default='%Y/%m/%d %H:%M:%S',
89 default='%Y/%m/%d %H:%M:%S',
90 )
90 )
91
91
92 _lastlogger = None
93
94 def _openlogfile(ui, vfs):
92 def _openlogfile(ui, vfs):
95 def rotate(oldpath, newpath):
93 def rotate(oldpath, newpath):
96 try:
94 try:
@@ -125,6 +123,21 b' def _openlogfile(ui, vfs):'
125 newpath=maxfiles > 0 and path + '.1')
123 newpath=maxfiles > 0 and path + '.1')
126 return vfs(name, 'a')
124 return vfs(name, 'a')
127
125
126 class proxylogger(object):
127 """Forward log events to another logger to be set later"""
128
129 def __init__(self):
130 self.logger = None
131
132 def tracked(self, event):
133 return self.logger is not None and self.logger.tracked(event)
134
135 def log(self, ui, event, msg, opts):
136 assert self.logger is not None
137 self.logger.log(ui, event, msg, opts)
138
139 _lastlogger = proxylogger()
140
128 class blackboxlogger(object):
141 class blackboxlogger(object):
129 def __init__(self, ui):
142 def __init__(self, ui):
130 self._repo = None
143 self._repo = None
@@ -143,19 +156,11 b' class blackboxlogger(object):'
143 return b'*' in self._trackedevents or event in self._trackedevents
156 return b'*' in self._trackedevents or event in self._trackedevents
144
157
145 def log(self, ui, event, msg, opts):
158 def log(self, ui, event, msg, opts):
146 global _lastlogger
147 if self._bbvfs:
159 if self._bbvfs:
148 _lastlogger = self
160 _lastlogger.logger = self
149 elif _lastlogger and _lastlogger._bbvfs:
150 # certain logger instances exist outside the context of
151 # a repo, so just default to the last blackbox logger that
152 # was seen.
153 pass
154 else:
161 else:
155 return
162 return
156 _lastlogger._log(ui, event, msg, opts)
157
163
158 def _log(self, ui, event, msg, opts):
159 default = ui.configdate('devel', 'default-date')
164 default = ui.configdate('devel', 'default-date')
160 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
165 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
161 user = procutil.getuser()
166 user = procutil.getuser()
@@ -187,7 +192,7 b' class blackboxlogger(object):'
187 self._repo = repo
192 self._repo = repo
188
193
189 def uipopulate(ui):
194 def uipopulate(ui):
190 ui.setlogger(b'blackbox', blackboxlogger(ui))
195 ui.setlogger(b'blackbox', _lastlogger)
191
196
192 def reposetup(ui, repo):
197 def reposetup(ui, repo):
193 # During 'hg pull' a httppeer repo is created to represent the remote repo.
198 # During 'hg pull' a httppeer repo is created to represent the remote repo.
@@ -200,14 +205,12 b' def reposetup(ui, repo):'
200 # instantiated per repository.
205 # instantiated per repository.
201 logger = blackboxlogger(ui)
206 logger = blackboxlogger(ui)
202 ui.setlogger(b'blackbox', logger)
207 ui.setlogger(b'blackbox', logger)
203 if logger:
208 logger.setrepo(repo)
204 logger.setrepo(repo)
205
209
206 # Set _lastlogger even if ui.log is not called. This gives blackbox a
210 # Set _lastlogger even if ui.log is not called. This gives blackbox a
207 # fallback place to log.
211 # fallback place to log
208 global _lastlogger
212 if _lastlogger.logger is None:
209 if _lastlogger is None:
213 _lastlogger.logger = logger
210 _lastlogger = logger
211
214
212 repo._wlockfreeprefix.add('blackbox.log')
215 repo._wlockfreeprefix.add('blackbox.log')
213
216
General Comments 0
You need to be logged in to leave comments. Login now