Show More
@@ -127,75 +127,73 b' def _openlogfile(ui, vfs):' | |||||
127 | newpath=maxfiles > 0 and path + '.1') |
|
127 | newpath=maxfiles > 0 and path + '.1') | |
128 | return vfs(name, 'a') |
|
128 | return vfs(name, 'a') | |
129 |
|
129 | |||
130 | if True: |
|
130 | class blackboxlogger(object): | |
131 | class blackboxlogger(object): |
|
131 | def __init__(self, ui): | |
132 | def __init__(self, ui): |
|
132 | self.track = ui.configlist('blackbox', 'track') | |
133 | self.track = ui.configlist('blackbox', 'track') |
|
|||
134 |
|
133 | |||
135 |
|
|
134 | @property | |
136 |
|
|
135 | def _bbvfs(self): | |
137 |
|
|
136 | vfs = None | |
138 |
|
|
137 | repo = getattr(self, '_bbrepo', None) | |
139 |
|
|
138 | if repo: | |
140 |
|
|
139 | vfs = repo.vfs | |
141 |
|
|
140 | if not vfs.isdir('.'): | |
142 |
|
|
141 | vfs = None | |
143 |
|
|
142 | return vfs | |
144 |
|
143 | |||
145 |
|
|
144 | def log(self, ui, event, msg, opts): | |
146 |
|
|
145 | global _lastlogger | |
147 |
|
|
146 | if not '*' in self.track and not event in self.track: | |
148 |
|
|
147 | return | |
149 |
|
148 | |||
150 |
|
|
149 | if self._bbvfs: | |
151 |
|
|
150 | _lastlogger = self | |
152 |
|
|
151 | elif _lastlogger and _lastlogger._bbvfs: | |
153 |
|
|
152 | # certain logger instances exist outside the context of | |
154 |
|
|
153 | # a repo, so just default to the last blackbox logger that | |
155 |
|
|
154 | # was seen. | |
156 |
|
|
155 | pass | |
157 |
|
|
156 | else: | |
158 |
|
|
157 | return | |
159 |
|
|
158 | _lastlogger._log(ui, event, msg, opts) | |
160 |
|
159 | |||
161 |
|
|
160 | def _log(self, ui, event, msg, opts): | |
162 |
|
|
161 | if getattr(self, '_bbinlog', False): | |
163 |
|
|
162 | # recursion and failure guard | |
164 |
|
|
163 | return | |
165 |
|
|
164 | self._bbinlog = True | |
166 |
|
|
165 | default = ui.configdate('devel', 'default-date') | |
167 |
|
|
166 | date = dateutil.datestr(default, ui.config('blackbox', 'date-format')) | |
168 | ui.config('blackbox', 'date-format')) |
|
167 | user = procutil.getuser() | |
169 |
|
|
168 | pid = '%d' % procutil.getpid() | |
170 | pid = '%d' % procutil.getpid() |
|
169 | formattedmsg = msg[0] % msg[1:] | |
171 | formattedmsg = msg[0] % msg[1:] |
|
170 | rev = '(unknown)' | |
172 | rev = '(unknown)' |
|
171 | changed = '' | |
173 | changed = '' |
|
172 | ctx = self._bbrepo[None] | |
174 | ctx = self._bbrepo[None] |
|
173 | parents = ctx.parents() | |
175 | parents = ctx.parents() |
|
174 | rev = ('+'.join([hex(p.node()) for p in parents])) | |
176 | rev = ('+'.join([hex(p.node()) for p in parents])) |
|
175 | if (ui.configbool('blackbox', 'dirty') and | |
177 | if (ui.configbool('blackbox', 'dirty') and |
|
176 | ctx.dirty(missing=True, merge=False, branch=False)): | |
178 | ctx.dirty(missing=True, merge=False, branch=False)): |
|
177 | changed = '+' | |
179 | changed = '+' |
|
178 | if ui.configbool('blackbox', 'logsource'): | |
180 | if ui.configbool('blackbox', 'logsource'): |
|
179 | src = ' [%s]' % event | |
181 | src = ' [%s]' % event |
|
180 | else: | |
182 |
|
|
181 | src = '' | |
183 | src = '' |
|
182 | try: | |
184 | try: |
|
183 | fmt = '%s %s @%s%s (%s)%s> %s' | |
185 | fmt = '%s %s @%s%s (%s)%s> %s' |
|
184 | args = (date, user, rev, changed, pid, src, formattedmsg) | |
186 | args = (date, user, rev, changed, pid, src, formattedmsg) |
|
185 | with _openlogfile(ui, self._bbvfs) as fp: | |
187 | with _openlogfile(ui, self._bbvfs) as fp: |
|
186 | fp.write(fmt % args) | |
188 | fp.write(fmt % args) |
|
187 | except (IOError, OSError) as err: | |
189 | except (IOError, OSError) as err: |
|
188 | ui.debug('warning: cannot write to blackbox.log: %s\n' % | |
190 | ui.debug('warning: cannot write to blackbox.log: %s\n' % |
|
189 | encoding.strtolocal(err.strerror)) | |
191 | encoding.strtolocal(err.strerror)) |
|
190 | # do not restore _bbinlog intentionally to avoid failed | |
192 | # do not restore _bbinlog intentionally to avoid failed |
|
191 | # logging again | |
193 | # logging again |
|
192 | else: | |
194 |
else |
|
193 | self._bbinlog = False | |
195 | self._bbinlog = False |
|
|||
196 |
|
194 | |||
197 |
|
|
195 | def setrepo(self, repo): | |
198 |
|
|
196 | self._bbrepo = repo | |
199 |
|
197 | |||
200 | def wrapui(ui): |
|
198 | def wrapui(ui): | |
201 | class blackboxui(ui.__class__): |
|
199 | class blackboxui(ui.__class__): |
General Comments 0
You need to be logged in to leave comments.
Login now