From b44e8167d7f44bf06c450a2b577d2d82b065762a Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 10 Feb 2017 18:15:14 +0900 Subject: [PATCH] Enhance error logging - Prevent to fall into error logging recursion when it doesn't have request info (Print 'Unknown' when the request is still `None` - Print repr(e) rather than str(e) --- sanic/server.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 99652fc9..e58bb181 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -179,7 +179,8 @@ class HttpProtocol(asyncio.Protocol): self.request.ip)) except Exception as e: self.bail_out( - "Writing response failed, connection closed {}".format(e)) + "Writing response failed, connection closed {}".format( + repr(e))) finally: if not keep_alive: self.transport.close() @@ -196,10 +197,10 @@ class HttpProtocol(asyncio.Protocol): except RuntimeError: log.error( 'Connection lost before error written @ {}'.format( - self.request.ip)) + self.request.ip if self.request else 'Unknown')) except Exception as e: self.bail_out( - "Writing error failed, connection closed {}".format(e), + "Writing error failed, connection closed {}".format(repr(e)), from_error=True) finally: self.transport.close()