From 8d62de0b8726625e81e300b1ac9e92d2f5a705a8 Mon Sep 17 00:00:00 2001 From: Shaw Terwilliger Date: Thu, 24 Sep 2015 09:29:56 -0400 Subject: [PATCH 1/2] Extend precision of access log "T" to milliseconds The fractional time part had a precision of 10 milliseconds due to a too-short truncation of the time string. This commit adds one digit and includes a test for the case. --- aiohttp/helpers.py | 2 +- tests/test_helpers.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 0a34f9a1bc8..eb542ba96b0 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -254,7 +254,7 @@ def atoms(message, environ, response, transport, request_time): 'f': headers.get(hdrs.REFERER, '-'), 'a': headers.get(hdrs.USER_AGENT, '-'), 'T': str(int(request_time)), - 'D': str(request_time).split('.', 1)[-1][:5], + 'D': str(request_time).split('.', 1)[-1][:6], 'p': "<%s>" % os.getpid() } diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 875e99fa28f..fd8bd80fe90 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,3 +1,4 @@ +import datetime import unittest import unittest.mock @@ -116,6 +117,17 @@ def prop(self): a.prop = 123 +class TestAtoms(unittest.TestCase): + + def test_get_seconds_and_milliseconds(self): + response = dict(status=200, output_length=1) + request_time = 321.012345678901234 + + atoms = helpers.atoms(None, None, response, None, request_time) + self.assertEqual(atoms['T'], '321') + self.assertEqual(atoms['D'], '012345') + + class TestSafeAtoms(unittest.TestCase): def test_get_non_existing(self): From 583280dadad1e6d3667e1e853e8ba0baaa306ea5 Mon Sep 17 00:00:00 2001 From: Shaw Terwilliger Date: Thu, 24 Sep 2015 11:14:03 -0400 Subject: [PATCH 2/2] Fixed pyflakes warning about unused datetime --- tests/test_helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index fd8bd80fe90..dc9e94be4a6 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,4 +1,3 @@ -import datetime import unittest import unittest.mock