From f2da77e3694b1cb932ea02fa45f8b2777db73822 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Sat, 26 Aug 2023 14:38:00 +0100 Subject: [PATCH 1/2] Allow time format in translogger to be configured by kwarg If no arg is provided, a default_time_format is used. Fixes #73 --- paste/translogger.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/paste/translogger.py b/paste/translogger.py index 794efd88..56d2831e 100644 --- a/paste/translogger.py +++ b/paste/translogger.py @@ -17,8 +17,14 @@ class TransLogger(object): If ``setup_console_handler`` is true, then messages for the named logger will be sent to the console. + + To adjust the format of the timestamp in the log, provide a strftime + format string to the ``time_format`` keyword argument. Otherwise + ``default_time_format`` will be used. """ + default_time_format = '%d/%b/%Y:%H:%M:%S ' + format = ('%(REMOTE_ADDR)s - %(REMOTE_USER)s [%(time)s] ' '"%(REQUEST_METHOD)s %(REQUEST_URI)s %(HTTP_VERSION)s" ' '%(status)s %(bytes)s "%(HTTP_REFERER)s" "%(HTTP_USER_AGENT)s"') @@ -29,9 +35,11 @@ def __init__(self, application, logging_level=logging.INFO, logger_name='wsgi', setup_console_handler=True, - set_logger_level=logging.DEBUG): + set_logger_level=logging.DEBUG, + time_format=None): if format is not None: self.format = format + self.time_format = time_format or self.default_time_format self.application = application self.logging_level = logging_level self.logger_name = logger_name @@ -90,7 +98,7 @@ def write_log(self, environ, method, req_uri, start, status, bytes): 'REQUEST_METHOD': method, 'REQUEST_URI': req_uri, 'HTTP_VERSION': environ.get('SERVER_PROTOCOL'), - 'time': time.strftime('%d/%b/%Y:%H:%M:%S ', start) + offset, + 'time': time.strftime(self.time_format, start) + offset, 'status': status.split(None, 1)[0], 'bytes': bytes, 'HTTP_REFERER': environ.get('HTTP_REFERER', '-'), From 9c4b8cf363c9627aa8489260110c44982cae405b Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Sat, 26 Aug 2023 14:41:09 +0100 Subject: [PATCH 2/2] remove support in tests for python 2.7 --- .github/workflows/tests.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5eaa2c24..29a8ef4c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,8 +6,6 @@ jobs: strategy: matrix: include: - - python: 2.7 - env: py27 - python: 3.5 env: py35 - python: 3.6