[Twisted-Python] Problem Changing Time Format of a Log
Hi Folks:
I need to change date format of a log - the
application I am using wants HH:MM:SS. Twisted seems
to give back HH:MM.
Based on the example in Abe Fettig's book and looking
at Twisted.Python.Log (and I am not sure where to
define the timeFormat string), I do the following.
class MyLog(log.FileLogObserver):
def formatTime(self, when):
if self.timeFormat is not None:
return time.strftime(self.timeFormat,
time.localtime(when))
tzOffset = -self.getTimezoneOffset()
when = datetime.datetime.utcfromtimestamp(when
+ tzOffset)
tzHour = int(tzOffset / 60 / 60)
tzMin = int(tzOffset / 60 % 60)
# added seconds
return '%d/%02d/%02d %02d:%02d:%02d %+03d%02d'
% (
when.year, when.month, when.day,
when.hour, when.minute, when.second,
tzHour, tzMin)
def emit(self, logEntryDict):
log.FileLogObserver.emit(self, logEntryDict)
When I run my code in twistd, I get the following
error
Log observer
On 5/2/08, Andrew Francis
I need to change date format of a log - the application I am using wants HH:MM:SS. Twisted seems to give back HH:MM.
I can't comment on your code, but I noticed that Twisted's default logging format changed with the release of 8.0 to be HH:MM:SS, so you may just want to upgrade. Also, I think it now uses the builtin python logging module, so changes to the format might now be easier. Cameron
On May 2, 2008, at 9:54 AM, Andrew Francis wrote:
Log observer
failed, removing from observer list.
Does this mean that the the method raised an exception but the twisted logging infrastructure isn't telling you what the exception was? I've done this successfully: http://allmydata.org/trac/tahoe/browser/src/allmydata/node.py? rev=2360#L201 Regards, Zooko
participants (3)
-
Andrew Francis
-
Cameron Dale
-
zooko