-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve access logging #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f157e32
7114db4
96aa607
87f8e17
ac9b967
d09955e
4107678
9b0de23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from html import escape as html_escape | ||
|
||
import aiohttp | ||
from aiohttp import errors, streams, hdrs, helpers | ||
from aiohttp import errors, streams, hdrs | ||
from aiohttp.log import server_logger | ||
|
||
__all__ = ('ServerHttpProtocol',) | ||
|
@@ -26,8 +26,7 @@ | |
</body> | ||
</html>""" | ||
|
||
ACCESS_LOG_FORMAT = ( | ||
'%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"') | ||
ACCESS_LOG_FORMAT = '%a %l %u %t "%r" %s %b "%{Referrer}i" "%{User-Agent}i"' | ||
|
||
|
||
if hasattr(socket, 'SO_KEEPALIVE'): | ||
|
@@ -68,8 +67,8 @@ class ServerHttpProtocol(aiohttp.StreamProtocol): | |
:param logger: custom logger object | ||
:type logger: aiohttp.log.server_logger | ||
|
||
:param access_log: custom logging object | ||
:type access_log: aiohttp.log.server_logger | ||
:param access_logger: access logging object | ||
:type access_log: helpers.AccessLogger | ||
|
||
:param str access_log_format: access log format string | ||
|
||
|
@@ -90,8 +89,7 @@ def __init__(self, *, loop=None, | |
keep_alive_on=True, | ||
timeout=0, | ||
logger=server_logger, | ||
access_log=None, | ||
access_log_format=ACCESS_LOG_FORMAT, | ||
access_logger=None, | ||
host="", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Backward incompatible change: you've dropped two params and added another one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works even slower then current implementation if AccessLogger created in the constructor. Converting from %h -> %(h)s takes too much time. I have one idea have to leave current signatures and make it work faster, but then access_log_format will be not apache compatible. It would be something like: ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What's about adding If Make sure Feel free to making |
||
port=0, | ||
debug=False, | ||
|
@@ -110,8 +108,7 @@ def __init__(self, *, loop=None, | |
self.port = port | ||
self.logger = log or logger | ||
self.debug = debug | ||
self.access_log = access_log | ||
self.access_log_format = access_log_format | ||
self.access_logger = access_logger | ||
|
||
@property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep |
||
def keep_alive_timeout(self): | ||
|
@@ -187,17 +184,9 @@ def keep_alive(self, val): | |
self._keep_alive = val | ||
|
||
def log_access(self, message, environ, response, time): | ||
if self.access_log and self.access_log_format: | ||
try: | ||
environ = environ if environ is not None else {} | ||
atoms = helpers.SafeAtoms( | ||
helpers.atoms( | ||
message, environ, response, self.transport, time), | ||
getattr(message, 'headers', None), | ||
getattr(response, 'headers', None)) | ||
self.access_log.info(self.access_log_format % atoms) | ||
except: | ||
self.logger.error(traceback.format_exc()) | ||
if self.access_logger: | ||
self.access_logger.log(message, environ, response, | ||
self.transport, time) | ||
|
||
def log_debug(self, *args, **kw): | ||
if self.debug: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
upstr(key)
instead ofkey.upper()
call.