RotatingFileHandler
Robert Brewer
fumanchu at amor.org
Thu Dec 2 16:53:03 EST 2004
Kamus of Kadizhar wrote:
> I'm having a problem with logging. I have an older app that used the
> RotatingFileHandler before it became part of the main distribution (I
> guess in 2.3).
>
> It worked fine then. Now I get:
>
> [yan at hermes bin]# ./mplayer.py file://test.avi
> //test.avi
> Traceback (most recent call last):
> File "./mplayer.py", line 40, in ?
> logFile.emit(movieName)
> File
> "/usr/src/build/394694-i386/install/usr/lib/python2.3/logging/
> handlers.py", line 102, in emit
> File
> "/usr/src/build/394694-i386/install/usr/lib/python2.3/logging/
> __init__.py", line 567, in format
> File
> "/usr/src/build/394694-i386/install/usr/lib/python2.3/logging/
> __init__.py", line 362, in format
> AttributeError: 'str' object has no attribute 'getMessage'
>
> The offending snippet of code is:
>
> logFile =
> logging.handlers.RotatingFileHandler('/var/log/user/movies2.lo
> g','a',2000,4)
> logFile.emit(movieName)
Making a quick run-through of the logging module, it looks like you need
to have a Formatter object added to your Handler:
filename = '/var/log/user/movies2.log'
logFile = logging.handlers.RotatingFileHandler(filename,'a',2000,4)
formatter = logging.Formatter()
logFile.setFormatter(formatter)
...then you can call emit.
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list