[Twisted-Python] Setting a different logger for Twistd

Landreville landreville at deadtreepages.com
Tue Jun 8 11:06:56 EDT 2010


On Tue, Jun 8, 2010 at 10:46 AM, Landreville
<landreville at deadtreepages.com> wrote:
> Hello,
> I saw a few tickets and some mailing list messages similar to this
> question, but never saw a definitive answer.
>
> How do I go about using a different logger when I am using twistd?
>
> I have a file that defines the application object and I tried the
> following code in hopes that I could make the logger have max rotated
> logs set to a smaller number:
>
> logfile = LogFile(LOG_FILE, LOG_DIRECTORY, LOG_SIZE, maxRotatedFiles=MAX_LOGS)
> application.setComponent(ILogObserver, FileLogObserver(logfile))
>
> but I get an assertion error coming up:
> Traceback (most recent call last):
>  File "/usr/bin/twistd", line 21, in <module>
>    run()
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/scripts/twistd.py",
> line 27, in run
>    app.run(runApp, ServerOptions)
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/application/app.py",
> line 693, in run
>    runApp(config)
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/scripts/twistd.py",
> line 23, in runApp
>    _SomeApplicationRunner(config).run()
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/application/app.py",
> line 421, in run
>    self.logger.start(self.application)
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/application/app.py",
> line 249, in start
>    log.startLoggingWithObserver(self._observer)
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/python/log.py",
> line 592, in startLoggingWithObserver
>    addObserver(observer)
>  File "/Library/Python/2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.6-universal.egg/twisted/python/log.py",
> line 253, in addObserver
>    assert callable(other)
> AssertionError
>

ahh.. I missed the .emit in the docs. It should have been:
logfile = LogFile(LOG_FILE, LOG_DIRECTORY, LOG_SIZE, maxRotatedFiles=MAX_LOGS)
logfunc = FileLogObserver(logfile).emit
application.setComponent(ILogObserver, logfunc)



More information about the Twisted-Python mailing list