Add TRACE level logging

This commit is contained in:
Job Evers-Meltzer 2016-12-14 16:46:06 -06:00
parent f181af8547
commit 3585d861ff
4 changed files with 21 additions and 9 deletions

View file

@ -33,6 +33,7 @@ _srcfile = os.path.normcase(_srcfile)
session = FuturesSession() session = FuturesSession()
TRACE = 5
def bg_cb(sess, resp): def bg_cb(sess, resp):
@ -371,5 +372,10 @@ class Logger(logging.Logger):
callback(err, *args, **kwargs) callback(err, *args, **kwargs)
return _fail return _fail
def trace(self, msg, *args, **kwargs):
if self.isEnabledFor(TRACE):
self._log(TRACE, msg, args, **kwargs)
logging.setLoggerClass(Logger) logging.setLoggerClass(Logger)
logging.addLevelName(TRACE, 'TRACE')

View file

@ -64,7 +64,7 @@ class ServerProtocol(Protocol):
self.transport.loseConnection() self.transport.loseConnection()
def write(self, data): def write(self, data):
log.debug("Writing %s bytes of data to the transport", str(len(data))) log.trace("Writing %s bytes of data to the transport", len(data))
self.transport.write(data) self.transport.write(data)
self.factory.rate_limiter.report_ul_bytes(len(data)) self.factory.rate_limiter.report_ul_bytes(len(data))

View file

@ -52,11 +52,13 @@ class ServerRequestHandler(object):
from twisted.internet import reactor from twisted.internet import reactor
if self.production_paused is False: if self.production_paused:
return
chunk = self.response_buff[:self.CHUNK_SIZE] chunk = self.response_buff[:self.CHUNK_SIZE]
self.response_buff = self.response_buff[self.CHUNK_SIZE:] self.response_buff = self.response_buff[self.CHUNK_SIZE:]
if chunk != '': if chunk == '':
log.debug("writing %s bytes to the client", str(len(chunk))) return
log.trace("writing %s bytes to the client", len(chunk))
self.consumer.write(chunk) self.consumer.write(chunk)
reactor.callLater(0, self._produce_more) reactor.callLater(0, self._produce_more)
@ -79,7 +81,7 @@ class ServerRequestHandler(object):
def get_more_data(): def get_more_data():
if self.producer is not None: if self.producer is not None:
log.debug("Requesting more data from the producer") log.trace("Requesting more data from the producer")
self.producer.resumeProducing() self.producer.resumeProducing()
reactor.callLater(0, get_more_data) reactor.callLater(0, get_more_data)

View file

@ -0,0 +1,4 @@
# log_support setups the default Logger class
# and so we need to ensure that it is also
# setup for the tests
from lbrynet.core import log_support