summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2015-08-23 20:44:14 -0400
committerBarry Warsaw2015-08-23 20:44:14 -0400
commit3f550a975a0def1dafbd4e060b01f0553ef2967f (patch)
tree608591b95950b665a8f5ec36eb4066cbf28cef85
parentc265a58eea8bb7abbdaa4cdbc0f25cafb1d78626 (diff)
downloadmailman-3f550a975a0def1dafbd4e060b01f0553ef2967f.tar.gz
mailman-3f550a975a0def1dafbd4e060b01f0553ef2967f.tar.zst
mailman-3f550a975a0def1dafbd4e060b01f0553ef2967f.zip
-rw-r--r--src/mailman/rest/wsgiapp.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/mailman/rest/wsgiapp.py b/src/mailman/rest/wsgiapp.py
index 94f654217..06bd9d2b9 100644
--- a/src/mailman/rest/wsgiapp.py
+++ b/src/mailman/rest/wsgiapp.py
@@ -32,7 +32,7 @@ from falcon.routing import create_http_method_map
from mailman.config import config
from mailman.database.transaction import transactional
from mailman.rest.root import Root
-from wsgiref.simple_server import WSGIRequestHandler
+from wsgiref.simple_server import WSGIRequestHandler, WSGIServer
from wsgiref.simple_server import make_server as wsgi_server
@@ -42,6 +42,16 @@ SLASH = '/'
+class AdminWSGIServer(WSGIServer):
+ """Server class that integrates error handling with our log files."""
+
+ def handle_error(self, request, client_address):
+ # Interpose base class method so that the exception gets printed to
+ # our log file rather than stderr.
+ log.exception('Exception happened during request from %s',
+ client_address)
+
+
class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler):
"""Handler class which just logs output to the right place."""
@@ -49,6 +59,16 @@ class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler):
"""See `BaseHTTPRequestHandler`."""
log.info('%s - - %s', self.address_string(), format % args)
+ def get_stderr(self):
+ # Return a fake stderr object that will actually write its output to
+ # the log file.
+ class StderrLogger:
+ def write(self, message):
+ log.exception('Client error')
+ def flush(self):
+ pass
+ return StderrLogger()
+
class SetAPIVersion:
"""Falcon middleware object that sets the api_version on resources."""
@@ -176,5 +196,6 @@ def make_server():
port = int(config.webservice.port)
server = wsgi_server(
host, port, make_application(),
+ server_class=AdminWSGIServer,
handler_class=AdminWebServiceWSGIRequestHandler)
return server