140 if not lastui or repo: |
140 if not lastui or repo: |
141 lastui = ui |
141 lastui = ui |
142 if getattr(ui, '_bbinlog', False): |
142 if getattr(ui, '_bbinlog', False): |
143 # recursion and failure guard |
143 # recursion and failure guard |
144 return |
144 return |
|
145 ui._bbinlog = True |
|
146 default = self.configdate('devel', 'default-date') |
|
147 date = util.datestr(default, '%Y/%m/%d %H:%M:%S') |
|
148 user = util.getuser() |
|
149 pid = '%d' % util.getpid() |
|
150 formattedmsg = msg[0] % msg[1:] |
|
151 rev = '(unknown)' |
|
152 changed = '' |
|
153 if repo: |
|
154 ctx = repo[None] |
|
155 parents = ctx.parents() |
|
156 rev = ('+'.join([hex(p.node()) for p in parents])) |
|
157 if (ui.configbool('blackbox', 'dirty') and |
|
158 ctx.dirty(missing=True, merge=False, branch=False)): |
|
159 changed = '+' |
|
160 if ui.configbool('blackbox', 'logsource'): |
|
161 src = ' [%s]' % event |
|
162 else: |
|
163 src = '' |
145 try: |
164 try: |
146 ui._bbinlog = True |
165 fmt = '%s %s @%s%s (%s)%s> %s' |
147 default = self.configdate('devel', 'default-date') |
166 args = (date, user, rev, changed, pid, src, formattedmsg) |
148 date = util.datestr(default, '%Y/%m/%d %H:%M:%S') |
167 with ui._openlogfile() as fp: |
149 user = util.getuser() |
168 fp.write(fmt % args) |
150 pid = '%d' % util.getpid() |
169 except (IOError, OSError) as err: |
151 formattedmsg = msg[0] % msg[1:] |
170 self.debug('warning: cannot write to blackbox.log: %s\n' % |
152 rev = '(unknown)' |
171 err.strerror) |
153 changed = '' |
172 # do not restore _bbinlog intentionally to avoid failed |
154 if repo: |
173 # logging again |
155 ctx = repo[None] |
174 else: |
156 parents = ctx.parents() |
175 ui._bbinlog = False |
157 rev = ('+'.join([hex(p.node()) for p in parents])) |
|
158 if (ui.configbool('blackbox', 'dirty') and |
|
159 ctx.dirty(missing=True, merge=False, branch=False)): |
|
160 changed = '+' |
|
161 if ui.configbool('blackbox', 'logsource'): |
|
162 src = ' [%s]' % event |
|
163 else: |
|
164 src = '' |
|
165 try: |
|
166 fmt = '%s %s @%s%s (%s)%s> %s' |
|
167 args = (date, user, rev, changed, pid, src, formattedmsg) |
|
168 with ui._openlogfile() as fp: |
|
169 fp.write(fmt % args) |
|
170 except (IOError, OSError) as err: |
|
171 self.debug('warning: cannot write to blackbox.log: %s\n' % |
|
172 err.strerror) |
|
173 # do not restore _bbinlog intentionally to avoid failed |
|
174 # logging again |
|
175 else: |
|
176 ui._bbinlog = False |
|
177 finally: |
|
178 pass |
|
179 |
176 |
180 def setrepo(self, repo): |
177 def setrepo(self, repo): |
181 self._bbrepo = repo |
178 self._bbrepo = repo |
182 |
179 |
183 ui.__class__ = blackboxui |
180 ui.__class__ = blackboxui |