Skip to content

Commit

Permalink
Fix a bug which meant that requests were logged with an invalid times…
Browse files Browse the repository at this point in the history
…tamp (#86)
  • Loading branch information
richvdh authored Mar 24, 2020
1 parent 404b131 commit 9b1a1dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/86.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which meant that requests were logged with an invalid timestamp.
12 changes: 7 additions & 5 deletions sygnal/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,18 @@ class SygnalLoggedSite(server.Site):
Sygnal.
"""

def __init__(self, *args, reactor, log_formatter, **kwargs):
super().__init__(*args, reactor=reactor, **kwargs)
def __init__(self, *args, log_formatter, **kwargs):
super().__init__(*args, **kwargs)
self.log_formatter = log_formatter
self.reactor = reactor
self.logger = logging.getLogger("sygnal.access")

def log(self, request):
log_date_time = datetimeToLogString(self.reactor.seconds())
"""Log this request. Called by request.finish."""
# this also works around a bug in twisted.web.http.HTTPFactory which uses a
# monotonic time as an epoch time.
log_date_time = datetimeToLogString()
line = self.log_formatter(log_date_time, request)
self.logger.info("%s", line)
self.logger.info("Handled request: %s", line)


class PushGatewayApiServer(object):
Expand Down

0 comments on commit 9b1a1dd

Please sign in to comment.