Use logger for WSGIServer
Log exception from the WSGIServer. Exceptions from socket timeouts are currently written to stderr.
This commit is contained in:
parent
edebcf03c7
commit
7d687205bd
@ -36,7 +36,9 @@ import pprint
|
|||||||
import socket
|
import socket
|
||||||
import socketserver
|
import socketserver
|
||||||
import ssl
|
import ssl
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
import wsgiref.simple_server
|
import wsgiref.simple_server
|
||||||
import zlib
|
import zlib
|
||||||
import datetime
|
import datetime
|
||||||
@ -84,6 +86,7 @@ class HTTPServer(wsgiref.simple_server.WSGIServer):
|
|||||||
# These class attributes must be set before creating instance
|
# These class attributes must be set before creating instance
|
||||||
client_timeout = None
|
client_timeout = None
|
||||||
max_connections = None
|
max_connections = None
|
||||||
|
logger = None
|
||||||
|
|
||||||
def __init__(self, address, handler, bind_and_activate=True):
|
def __init__(self, address, handler, bind_and_activate=True):
|
||||||
"""Create server."""
|
"""Create server."""
|
||||||
@ -117,6 +120,13 @@ class HTTPServer(wsgiref.simple_server.WSGIServer):
|
|||||||
_socket.settimeout(self.client_timeout)
|
_socket.settimeout(self.client_timeout)
|
||||||
return _socket, address
|
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):
|
class HTTPSServer(HTTPServer):
|
||||||
"""HTTPS server."""
|
"""HTTPS server."""
|
||||||
|
@ -173,6 +173,7 @@ def serve(configuration, logger):
|
|||||||
server_class.client_timeout = configuration.getint("server", "timeout")
|
server_class.client_timeout = configuration.getint("server", "timeout")
|
||||||
server_class.max_connections = configuration.getint(
|
server_class.max_connections = configuration.getint(
|
||||||
"server", "max_connections")
|
"server", "max_connections")
|
||||||
|
server_class.logger = logger
|
||||||
|
|
||||||
RequestHandler.logger = logger
|
RequestHandler.logger = logger
|
||||||
if not configuration.getboolean("server", "dns_lookup"):
|
if not configuration.getboolean("server", "dns_lookup"):
|
||||||
|
Loading…
Reference in New Issue
Block a user