Ticket #4021: twisted-lesschatty.patch

File twisted-lesschatty.patch, 2.3 KB (added by bra, 5 years ago)

proposed patch, making twisted protocols less chatty by default

  • twisted/internet/udp.py

     
    9393        # Make sure that if we listened on port 0, we update that to 
    9494        # reflect what the OS actually assigned us. 
    9595        self._realPortNumber = skt.getsockname()[1] 
     96         
     97        if self.protocol.noisy: 
     98            log.msg("%s starting on %s"%(self.protocol.__class__, self._realPortNumber)) 
    9699 
    97         log.msg("%s starting on %s"%(self.protocol.__class__, self._realPortNumber)) 
    98  
    99100        self.connected = 1 
    100101        self.socket = skt 
    101102        self.fileno = self.socket.fileno 
     
    200201    def connectionLost(self, reason=None): 
    201202        """Cleans up my socket. 
    202203        """ 
    203         log.msg('(Port %s Closed)' % self._realPortNumber) 
     204        if self.protocol.noisy: 
     205            log.msg('(Port %s Closed)' % self._realPortNumber) 
    204206        self._realPortNumber = None 
    205207        base.BasePort.connectionLost(self, reason) 
    206208        if hasattr(self, "protocol"): 
  • twisted/internet/tcp.py

     
    857857        # Make sure that if we listened on port 0, we update that to 
    858858        # reflect what the OS actually assigned us. 
    859859        self._realPortNumber = skt.getsockname()[1] 
     860        if self.factory.noisy: 
     861            log.msg("%s starting on %s" % (self.factory.__class__, self._realPortNumber)) 
    860862 
    861         log.msg("%s starting on %s" % (self.factory.__class__, self._realPortNumber)) 
    862  
    863863        # The order of the next 6 lines is kind of bizarre.  If no one 
    864864        # can explain it, perhaps we should re-arrange them. 
    865865        self.factory.doStart() 
  • twisted/internet/protocol.py

     
    3434    protocol = None 
    3535 
    3636    numPorts = 0 
    37     noisy = True 
     37    noisy = False 
    3838 
    3939    def doStart(self): 
    4040        """Make sure startFactory is called. 
     
    516516 
    517517    transport = None 
    518518    numPorts = 0 
    519     noisy = True 
     519    noisy = False 
    520520 
    521521    def __getstate__(self): 
    522522        d = self.__dict__.copy()