diff --git a/eventlet/wsgi.py b/eventlet/wsgi.py index ef458aa..b1d18c6 100644 --- a/eventlet/wsgi.py +++ b/eventlet/wsgi.py @@ -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 diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index bc581a8..1bc6abb 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -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')