summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-06-15 18:18:05 +0100
committerErik Johnston <erik@matrix.org>2015-06-15 18:18:05 +0100
commitaaa749d366f768dd164f899c1d8e5eedd44ee5f5 (patch)
treea22fb1f2f6f2f03bb4f0415f7c438e8f90057852 /synapse/http
parentLog more when we have processed the request (diff)
downloadsynapse-aaa749d366f768dd164f899c1d8e5eedd44ee5f5.tar.xz
Disable twisted access logging. Move access logging to SynapseRequest object
Diffstat (limited to '')
-rw-r--r--synapse/http/server.py90
1 files changed, 32 insertions, 58 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 34645a371a..807ff95c65 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -79,65 +79,39 @@ def request_handler(request_handler):
         _next_request_id += 1
         with LoggingContext(request_id) as request_context:
             request_context.request = request_id
-            code = None
-            start = self.clock.time_msec()
-            try:
-                logger.info(
-                    "%s - Received request: %s %s",
-                    request.getClientIP(),
-                    request.method,
-                    request.get_redacted_uri()
-                )
-                d = request_handler(self, request)
-                with PreserveLoggingContext():
-                    yield d
-                code = request.code
-            except CodeMessageException as e:
-                code = e.code
-                if isinstance(e, SynapseError):
-                    logger.info(
-                        "%s SynapseError: %s - %s", request, code, e.msg
+            with request.processing():
+                try:
+                    d = request_handler(self, request)
+                    with PreserveLoggingContext():
+                        yield d
+                except CodeMessageException as e:
+                    code = e.code
+                    if isinstance(e, SynapseError):
+                        logger.info(
+                            "%s SynapseError: %s - %s", request, code, e.msg
+                        )
+                    else:
+                        logger.exception(e)
+                    outgoing_responses_counter.inc(request.method, str(code))
+                    respond_with_json(
+                        request, code, cs_exception(e), send_cors=True,
+                        pretty_print=_request_user_agent_is_curl(request),
+                        version_string=self.version_string,
+                    )
+                except:
+                    logger.exception(
+                        "Failed handle request %s.%s on %r: %r",
+                        request_handler.__module__,
+                        request_handler.__name__,
+                        self,
+                        request
+                    )
+                    respond_with_json(
+                        request,
+                        500,
+                        {"error": "Internal server error"},
+                        send_cors=True
                     )
-                else:
-                    logger.exception(e)
-                outgoing_responses_counter.inc(request.method, str(code))
-                respond_with_json(
-                    request, code, cs_exception(e), send_cors=True,
-                    pretty_print=_request_user_agent_is_curl(request),
-                    version_string=self.version_string,
-                )
-            except:
-                code = 500
-                logger.exception(
-                    "Failed handle request %s.%s on %r: %r",
-                    request_handler.__module__,
-                    request_handler.__name__,
-                    self,
-                    request
-                )
-                respond_with_json(
-                    request,
-                    500,
-                    {"error": "Internal server error"},
-                    send_cors=True
-                )
-            finally:
-                code = str(code) if code else "-"
-                end = self.clock.time_msec()
-                logger.info(
-                    "%s - %s - {%s}"
-                    " Processed request: %dms %sB %s \"%s %s %s\" \"%s\"",
-                    request.getClientIP(),
-                    request.site_tag,
-                    request.authenticated_entity,
-                    end-start,
-                    request.sentLength,
-                    code,
-                    request.method,
-                    request.get_redacted_uri(),
-                    request.clientproto,
-                    request.get_user_agent(),
-                )
     return wrapped_request_handler