253
248
self.write = f.write
254
249
self.flush = f.flush
251
def _safeFormat(self, fmtString, crap):
252
#There's a way we could make this if not safer at least more
253
#informative: perhaps some sort of str/repr wrapper objects
254
#could be wrapped around the things inside of 'crap'. That way
255
#if the event dict contains an object with a bad __repr__, we
256
#can only cry about that individual object instead of the
259
text = fmtString % crap
260
except KeyboardInterrupt:
264
text = ('Invalid format string or unformattable object in log message: %r, %s' % (fmtString, crap))
267
text = 'UNFORMATTABLE OBJECT WRITTEN TO LOG with fmt %r, MESSAGE LOST' % (fmtString,)
269
text = 'PATHOLOGICAL ERROR IN BOTH FORMAT STRING AND MESSAGE DETAILS, MESSAGE LOST'
256
272
def emit(self, eventDict):
257
273
edm = eventDict['message']
259
275
if eventDict['isError'] and eventDict.has_key('failure'):
260
276
text = eventDict['failure'].getTraceback()
261
277
elif eventDict.has_key('format'):
263
text = eventDict['format'] % eventDict
264
except KeyboardInterrupt:
268
text = ('Invalid format string in log message: %s'
271
text = 'UNFORMATTABLE OBJECT WRITTEN TO LOG, MESSAGE LOST'
278
text = self._safeFormat(eventDict['format'], eventDict)
273
280
# we don't know how to log this
276
text = ' '.join(map(str, edm))
283
text = ' '.join(map(reflect.safe_str, edm))
278
285
timeStr = time.strftime(self.timeFormat, time.localtime(eventDict['time']))
279
286
fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
280
msgStr = " [%(system)s] %(text)s\n" % fmtDict
287
msgStr = self._safeFormat("[%(system)s] %(text)s\n", fmtDict)
282
util.untilConcludes(self.write, timeStr + msgStr)
289
util.untilConcludes(self.write, timeStr + " " + msgStr)
283
290
util.untilConcludes(self.flush) # Hoorj!