[Twisted-Python] Problem Changing Time Format of a Log

Andrew Francis andrewfr_ice at yahoo.com
Fri May 2 11:54:32 EDT 2008

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,

        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

Log observer <bound method InsightLog.emit of <>
failed, removing from observer list.

Any help would be appreciated in telling me what is
going wrong, or pointing out the right way of altering
the log.


Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

More information about the Twisted-Python mailing list