My Twisted-based client sends UDP packets in a loop. Therefore I'm using the class DatagramProtocol. This is the source:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from twisted.application.service import Service
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from twisted.internet.protocol import DatagramProtocol
from twisted.python import log
import logging
class HeartbeatClient(Service):
def __init__(self, host, port, data, beat_period):
self.ip = host
self.port = int(port)
self.data = data
self.beat = int(beat_period)
def startService(self):
self._call = LoopingCall(self._heartbeat)
self._call.start(self.beat)
def stopService(self):
self._call.stop()
def _heartbeat(self):
protocol = DatagramProtocol()
protocol.noisy = False
port = reactor.listenUDP(0, protocol)
port.write(self.data, (self.ip, self.port))
port.stopListening()
now when I run this client with twistd, I permanently get log messages from the Twisted classes, namely from the class DatagramProtocol:
2011-09-11 18:39:25+0200 [-] (Port 55681 Closed)
2011-09-11 18:39:30+0200 [-] twisted.internet.protocol.DatagramProtocol starting on 44903
2011-09-11 18:39:30+0200 [-] (Port 44903 Closed)
2011-09-11 18:39:35+0200 [-] twisted.internet.protocol.DatagramProtocol starting on 50044
2011-09-11 18:39:35+0200 [-] (Port 50044 Closed)
2011-09-11 18:39:40+0200 [-] twisted.internet.protocol.DatagramProtocol starting on 37450
Since these log messages are polluting my "own" logs, I wonder if I can disable these log messages.
As you can see I already reduced the amount of logs by calling protocol.noisy = False
, but I'm still getting other Log messages. Also the command g = protocol.ClientFactory().noisy = False
does not help.
Is it possible to disable logging of all Twisted-internal classes, in a generic way - for ALL modules? Maybe by using some Twisted-logging configuration?