4

我正在使用twisted.web.client.Agent,而后者又使用HTTP11ClientProtocol。无数的工厂启动/停止消息掩盖了我真正感兴趣的消息。所以,我正在寻找一种方法来抑制它们。有没有?

2013-09-07 11:03:15+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x3183638>
2013-09-07 11:03:15+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x316d050>
2013-09-07 11:03:15+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x3183e18>
2013-09-07 11:03:16+0530 [HTTP11ClientProtocol,client] <twisted.web._newclient.Response object at 0x3185150>
2013-09-07 11:03:16+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x3183638>
2013-09-07 11:03:16+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x2dafa70>
2013-09-07 11:03:16+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x3184950>
2013-09-07 11:03:16+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x317c170>
2013-09-07 11:03:16+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x3186098>
2013-09-07 11:03:17+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x3171248>
2013-09-07 11:03:17+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x313ef80>
2013-09-07 11:03:17+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x311dbd8>
2013-09-07 11:03:17+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x31867a0>
2013-09-07 11:03:18+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x3171f80>
2013-09-07 11:03:18+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x3171ea8>
2013-09-07 11:03:18+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x311de60>
2013-09-07 11:03:18+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x316d4d0>
2013-09-07 11:03:19+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x325a830>
2013-09-07 11:03:19+0530 [-] Starting factory <twisted.web.client._HTTP11ClientFactory instance at 0x325eb90>
2013-09-07 11:03:20+0530 [HTTP11ClientProtocol,client] Stopping factory <twisted.web.client._HTTP11ClientFactory instance at 0x3183e18>

这(Twisted started/stopping factory/protocol less noise log messages)是一个类似的问题,但由于 HTTP11ClientProtocol 不是我正在实例化的东西,我无法弄清楚我将在哪里将属性噪声设置为 false。

4

2 回答 2

12

如果您希望_HTTP11ClientFactory应用程序中的每个都保持安静,您可以noisy在类级别设置属性:

from twisted.web import client
client._HTTP11ClientFactory.noisy = False

一种更灵活的方法是创建一个使用安静工厂的自定义,并在您需要更安静的日志时HTTPConnectionPool将其传递给您:Agent

from twisted.web import client

class QuietHTTP11ClientFactory(client._HTTP11ClientFactory):
    noisy = False

myQuietPool = client.HTTPConnectionPool(reactor)
myQuietPool._factory = QuietHTTP11ClientFactory

agent = client.Agent(reactor, pool=myQuietPool)
于 2013-09-07T12:42:47.597 回答
0

我能够在日志级别做到这一点:

import logging
logging.getLogger('twisted').setLevel(logging.CRITICAL)
于 2016-09-09T19:44:19.613 回答