How to suppress noisy factory started / stopped log messages from Twisted?

I use twisted.web.client.Agent, which in turn uses HTTP11ClientProtocol. Countless factory start / stop messages hide messages that really interest me. Therefore, I am looking for a way to suppress them. Whether there is a?

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> 

This ( Twisted start / stopping factory / protocol less noisy log messages ) is a similar question, but since HTTP11ClientProtocol is not what I am creating, I cannot figure out where I would set the property to noisy to false.

+4
source share
2 answers

If you want every _HTTP11ClientFactory in the application to disguise itself, you can simply set the noisy property at the class level:

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

A more flexible approach would be to create a custom HTTPConnectionPool that uses quiet factories and passes it to your Agent when you need a quieter log:

 from twisted.web import client class QuietHTTP11ClientFactory(client._HTTP11ClientFactory): noisy = False myQuietPool = client.HTTPConnectionPool(reactor) myQuietPool._factory = QuietHTTP11ClientFactory agent = client.Agent(reactor, pool=myQuietPool) 
+11
source

I was able to do this only at the logging level:

 import logging logging.getLogger('twisted').setLevel(logging.CRITICAL) 
0
source

Source: https://habr.com/ru/post/1501044/


All Articles