wsgi: log_output=False was not disabling startup and accepted messages
https://stackoverflow.com/questions/43211241/eventlet-wsgi-server-logging-wont-stop
This commit is contained in:
@@ -248,10 +248,27 @@ def get_logger(log, debug):
|
||||
and callable(getattr(log, 'debug', None)):
|
||||
return log
|
||||
else:
|
||||
return LoggerFileWrapper(log, debug)
|
||||
return LoggerFileWrapper(log or sys.stderr, debug)
|
||||
|
||||
|
||||
class LoggerFileWrapper(object):
|
||||
class LoggerNull(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def error(self, msg, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def info(self, msg, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def debug(self, msg, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def write(self, msg, *args):
|
||||
pass
|
||||
|
||||
|
||||
class LoggerFileWrapper(LoggerNull):
|
||||
def __init__(self, log, debug):
|
||||
self.log = log
|
||||
self._debug = debug
|
||||
@@ -678,10 +695,9 @@ class Server(BaseHTTPServer.HTTPServer):
|
||||
self.outstanding_requests = 0
|
||||
self.socket = socket
|
||||
self.address = address
|
||||
if log:
|
||||
self.log = LoggerNull()
|
||||
if log_output:
|
||||
self.log = get_logger(log, debug)
|
||||
else:
|
||||
self.log = get_logger(sys.stderr, debug)
|
||||
self.app = app
|
||||
self.keepalive = keepalive
|
||||
self.environ = environ
|
||||
|
@@ -217,7 +217,6 @@ def read_http(sock):
|
||||
class _TestBase(tests.LimitedTestCase):
|
||||
def setUp(self):
|
||||
super(_TestBase, self).setUp()
|
||||
self.logfile = six.StringIO()
|
||||
self.site = Site()
|
||||
self.killer = None
|
||||
self.set_site()
|
||||
@@ -234,6 +233,7 @@ class _TestBase(tests.LimitedTestCase):
|
||||
|
||||
Sets `self.server_addr` to (host, port) tuple suitable for `socket.connect`.
|
||||
"""
|
||||
self.logfile = six.StringIO()
|
||||
new_kwargs = dict(max_size=128,
|
||||
log=self.logfile,
|
||||
site=self.site)
|
||||
@@ -1572,6 +1572,16 @@ class TestHttpd(_TestBase):
|
||||
assert result.body == (b'HTTP_HOST: localhost\nHTTP_HTTP_X_ANY_K: two\n'
|
||||
b'HTTP_PATH_INFO: foo\nHTTP_X_ANY_K: one\n')
|
||||
|
||||
def test_log_disable(self):
|
||||
self.spawn_server(log_output=False)
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\npath-info: foo\r\n'
|
||||
b'x-ANY_k: one\r\nhttp-x-ANY_k: two\r\n\r\n')
|
||||
read_http(sock)
|
||||
sock.close()
|
||||
log_content = self.logfile.getvalue()
|
||||
assert log_content == ''
|
||||
|
||||
|
||||
def read_headers(sock):
|
||||
fd = sock.makefile('rb')
|
||||
|
Reference in New Issue
Block a user