Add reason to acccess log

This commit is contained in:
Andrew Rabert 2022-03-15 18:41:24 -04:00
parent 0c446ca73c
commit 0ff358a67e
2 changed files with 5 additions and 3 deletions

View file

@ -242,7 +242,7 @@ class Application(CallbackManager, web.Application):
log.access_log.log(
log_level,
'%s %s %s [%s] "%s %s %s" %d %s "%s" "%s" (secs:%.03f)',
'%s %s %s [%s] "%s %s %s" %d "%s" %s "%s" "%s" (secs:%.03f)',
handler.request.remote_ip,
'-', # RFC-1413 user identifier
handler.get_current_user() or '-',
@ -251,6 +251,7 @@ class Application(CallbackManager, web.Application):
handler.request.uri,
handler.request.version,
status,
handler._reason or '-',
bytes_written,
handler.request.headers.get('Referer', '-'),
handler.request.headers.get('User-Agent', '-'),

View file

@ -814,11 +814,12 @@ class AccessLogTests(sprockets.http.testing.SprocketsHttpTestCase):
when = datetime.datetime.fromtimestamp(request._start_time,
datetime.timezone.utc)
expected_message = re.compile(
r'^%s - - %s "%s %s %s" %d - "-" "-" \(secs:([^)]*)\)' %
r'^%s - - %s "%s %s %s" %d "%s" - "-" "-" \(secs:([^)]*)\)' %
(request.remote_ip,
re.escape(
when.strftime('[%d/%b/%Y:%H:%M:%S %z]')), request.method,
re.escape(request.uri), request.version, handler.get_status()))
re.escape(request.uri), request.version, handler.get_status(),
handler._reason))
message = context.records[0].getMessage()
match = expected_message.match(message)
if match is None: