Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #169 from c4urself/feature/named-loggers
Browse files Browse the repository at this point in the history
use named loggers
  • Loading branch information
lxyu committed Nov 9, 2015
2 parents 991b040 + cb143be commit b67c9dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions thriftpy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
)


logger = logging.getLogger(__name__)


class TServer(object):
def __init__(self, processor, trans,
itrans_factory=None, iprot_factory=None,
Expand Down Expand Up @@ -52,7 +55,7 @@ def serve(self):
except TTransportException:
pass
except Exception as x:
logging.exception(x)
logger.exception(x)

itrans.close()
otrans.close()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
13 changes: 8 additions & 5 deletions thriftpy/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit b67c9dd

Please sign in to comment.