From f50a37fc88b8157578787b93391e0054d4d06a82 Mon Sep 17 00:00:00 2001 From: lixxu Date: Tue, 28 Nov 2017 14:44:32 +0800 Subject: [PATCH 1/2] ignore error if request.ip is None --- sanic/server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index a475fd98..2d11d90f 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -312,13 +312,15 @@ class HttpProtocol(asyncio.Protocol): else: extra['byte'] = -1 + extra['host'] = 'UNKNOWN' if self.request is not None: - extra['host'] = '{0}:{1}'.format(self.request.ip[0], - self.request.ip[1]) + if self.request.ip: + extra['host'] = '{0}:{1}'.format(self.request.ip[0], + self.request.ip[1]) + extra['request'] = '{0} {1}'.format(self.request.method, self.request.url) else: - extra['host'] = 'UNKNOWN' extra['request'] = 'nil' access_logger.info('', extra=extra) From 283762224c3df3bbea9f3905274ba3b48bc98812 Mon Sep 17 00:00:00 2001 From: lixxu Date: Tue, 28 Nov 2017 14:47:43 +0800 Subject: [PATCH 2/2] clean codes --- sanic/server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 2d11d90f..0b82f1d3 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -315,8 +315,7 @@ class HttpProtocol(asyncio.Protocol): extra['host'] = 'UNKNOWN' if self.request is not None: if self.request.ip: - extra['host'] = '{0}:{1}'.format(self.request.ip[0], - self.request.ip[1]) + extra['host'] = '{0[0]}:{0[1]}'.format(self.request.ip) extra['request'] = '{0} {1}'.format(self.request.method, self.request.url)