From cb143bec5cad753adcbfe4c914c3aab5312c0988 Mon Sep 17 00:00:00 2001 From: Christian Verkerk Date: Sun, 8 Nov 2015 17:15:02 -0800 Subject: [PATCH] use named loggers --- thriftpy/server.py | 9 ++++++--- thriftpy/tornado.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/thriftpy/server.py b/thriftpy/server.py index 768a299..446e4a2 100644 --- a/thriftpy/server.py +++ b/thriftpy/server.py @@ -12,6 +12,9 @@ ) +logger = logging.getLogger(__name__) + + class TServer(object): def __init__(self, processor, trans, itrans_factory=None, iprot_factory=None, @@ -52,7 +55,7 @@ def serve(self): except TTransportException: pass except Exception as x: - logging.exception(x) + logger.exception(x) itrans.close() otrans.close() @@ -80,7 +83,7 @@ def serve(self): except KeyboardInterrupt: raise except Exception as x: - logging.exception(x) + logger.exception(x) def handle(self, client): itrans = self.itrans_factory.get_transport(client) @@ -93,7 +96,7 @@ def handle(self, client): except TTransportException: pass except Exception as x: - logging.exception(x) + logger.exception(x) itrans.close() otrans.close() diff --git a/thriftpy/tornado.py b/thriftpy/tornado.py index 2006823..6dded9d 100644 --- a/thriftpy/tornado.py +++ b/thriftpy/tornado.py @@ -35,6 +35,9 @@ import toro +logger = logging.getLogger(__name__) + + class TTornadoStreamTransport(TTransportBase): """a framed, buffered transport over a Tornado stream""" DEFAULT_CONNECT_TIMEOUT = timedelta(seconds=1) @@ -61,7 +64,7 @@ def with_timeout(self, timeout, future): @gen.coroutine def open(self, timeout=DEFAULT_CONNECT_TIMEOUT): - logging.debug('socket connecting') + logger.debug('socket connecting') sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) self.stream = iostream.IOStream(sock) @@ -117,10 +120,10 @@ def read_frame(self): raise iostream.StreamClosedError( 'Read zero bytes from stream') frame_length, = struct.unpack('!i', frame_header) - logging.debug('received frame header, frame length = %d', + logger.debug('received frame header, frame length = %d', frame_length) frame = yield self._read_bytes(frame_length) - logging.debug('received frame payload: %r', frame) + logger.debug('received frame payload: %r', frame) raise gen.Return(frame) def _read_bytes(self, n): @@ -183,10 +186,10 @@ def handle_stream(self, stream, address): self._processor.send_result(oprot, api, result, seqid) except Exception: - logging.exception('thrift exception in handle_stream') + logger.exception('thrift exception in handle_stream') trans.close() - logging.info('client disconnected %s:%d', host, port) + logger.info('client disconnected %s:%d', host, port) class TTornadoClient(TClient):