From 7d687205bd1db852d455db7231023eded2ae6511 Mon Sep 17 00:00:00 2001 From: Unrud Date: Fri, 10 Mar 2017 13:39:26 +0100 Subject: [PATCH] Use logger for WSGIServer Log exception from the WSGIServer. Exceptions from socket timeouts are currently written to stderr. --- radicale/__init__.py | 10 ++++++++++ radicale/__main__.py | 1 + 2 files changed, 11 insertions(+) diff --git a/radicale/__init__.py b/radicale/__init__.py index d188fbb..09f3d55 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -36,7 +36,9 @@ import pprint import socket import socketserver import ssl +import sys import threading +import traceback import wsgiref.simple_server import zlib import datetime @@ -84,6 +86,7 @@ class HTTPServer(wsgiref.simple_server.WSGIServer): # These class attributes must be set before creating instance client_timeout = None max_connections = None + logger = None def __init__(self, address, handler, bind_and_activate=True): """Create server.""" @@ -117,6 +120,13 @@ class HTTPServer(wsgiref.simple_server.WSGIServer): _socket.settimeout(self.client_timeout) return _socket, address + def handle_error(self, request, client_address): + if issubclass(sys.exc_info()[0], socket.timeout): + self.logger.error("connection timeout") + else: + self.logger.error( + "An exception occurred during request:\n%s", traceback.format_exc()) + class HTTPSServer(HTTPServer): """HTTPS server.""" diff --git a/radicale/__main__.py b/radicale/__main__.py index 2fce14c..79b410a 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -173,6 +173,7 @@ def serve(configuration, logger): server_class.client_timeout = configuration.getint("server", "timeout") server_class.max_connections = configuration.getint( "server", "max_connections") + server_class.logger = logger RequestHandler.logger = logger if not configuration.getboolean("server", "dns_lookup"):