Twisted: how to disable certain log messages?

I have XML-RPC methods in my application that generate a lot of Twisted log messages like this, which in turn are logged through the Python logging module:

2011-09-08 18:00:51.399553 UTC INFO XXX.XXX.XXX.XXX - - [08/Sep/2011:18:00:50 +0000] "POST /RPC2 HTTP/1.0" 200 129 "-" "xmlrpclib.py/1.0.1 (by www.pythonware.com)"

I do not need these log messages, and I would like to either change them to the logging.DEBUG level, or completely disable them. Is it supported?

EDIT . These are server-side log messages that are logged when invoking methods on twisted.web.xmlrpc.XMLRPC objects. These objects are used in the hierarchy (as in putChild ) under the twisted.web.server.Site and twisted.web.vhost.NameVirtualHost , and I use SelectReactor by default. I believe that any of these classes or the request object may be the one who actually registers them.

+4
source share
1 answer

twisted.web.xmlrpc.Proxy uses the factory to configure its HTTP connection (in the usual way). The noisy attribute at the Twisted factory provides control over whether they start the log and stop messages. You can change the noisy Proxy factory attribute as follows:

 from sys import stdout from twisted.web.xmlrpc import Proxy from twisted.internet import reactor from twisted.python.log import startLogging startLogging(stdout) p = Proxy('http://localhost:8080/RPC2') class QuietQueryFactory(p.queryFactory): noisy = False p.queryFactory = QuietQueryFactory p.callRemote('echo', 'foo') reactor.run() 

Compare with the program output if the noisy parameter noisy set to True .

For the XML-RPC server, log messages come from twisted.web.server.Site , which hosts the XML-RPC resource. The Site initializer takes the argument logPath ; if you pass the path for this parameter, then the query logs will be written to this path, and not to the main log. You can also override the Site.log method, which is what selects these log messages, either omit only those that you want to exclude, or do nothing to disable the entire request log.

+4
source

All Articles