Skip to content

Commit

Permalink
Fix logger report for unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jul 30, 2016
1 parent e2386a7 commit 8e8469b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,13 @@ def _format_o(key, args):

@staticmethod
def _format_a(args):
return args[3].get_extra_info('peername')[0] if args[3] is not None \
else '-'
if args[3] is None:
return '-'
peername = args[3].get_extra_info('peername')
if isinstance(peername, (list, tuple)):
return peername[0]
else:
return peername

@staticmethod
def _format_t(args):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ def test_access_logger_dicts():
mock_logger.info.assert_called_with(expected)


def test_access_logger_unix_socket():
log_format = '|%a|'
mock_logger = mock.Mock()
access_logger = helpers.AccessLogger(mock_logger, log_format)
message = mock.Mock(headers={"User-Agent": "Mock/1.0"}, version=(1, 1))
environ = {}
response = mock.Mock()
transport = mock.Mock()
transport.get_extra_info.return_value = ""
access_logger.log(message, environ, response, transport, 0.0)
assert not mock_logger.error.called
expected = '||'
mock_logger.info.assert_called_with(expected)


def test_logger_no_message_and_environ():
mock_logger = mock.Mock()
mock_transport = mock.Mock()
Expand Down

0 comments on commit 8e8469b

Please sign in to comment.