[Twisted-Python] Configuring Twisted logging via plugins

Valeriy Zamarayev valeriy.zamarayev at gmail.com
Wed Aug 4 22:44:43 MDT 2010


Hello, all.

There have been a few questions on this list about how to configure
Twisted logging via plugins, as opposed to .tac files. And we now know
about the #638 and #3534 tickets. Hopefully, they will be resolved
soon.

But before this happens, it seems to me there's no other way to handle
this than to use a "monkey patching" techinque on Twisted (excluding
patching the Twisted source code itself).

We need to access the 'application' object when the server starts. We
can do this when the 'twistd' code calls setServiceParent on the
service returned by the plugin. So if we wrap setServiceParent, we can
access the application object and do what we want.

See the code:  http://gist.github.com/505926

This works for me. I don't know if a better and less dangerous way to
achieve the same exists. Maybe there is one?

Best Regards,
Valeriy





More information about the Twisted-Python mailing list