diff --git a/socketio/server.py b/socketio/server.py index 1b57b5a3..e4b1aa53 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -85,12 +85,14 @@ def __init__(self, client_manager_class=None, logger=False, binary=False, if not isinstance(logger, bool): self.logger = logger else: - logging.basicConfig() self.logger = logging.getLogger('socketio') - if logger: - self.logger.setLevel(logging.INFO) - else: - self.logger.setLevel(logging.ERROR) + if not logging.root.handlers and \ + self.logger.level == logging.NOTSET: + if logger: + self.logger.setLevel(logging.INFO) + else: + self.logger.setLevel(logging.ERROR) + self.logger.addHandler(logging.StreamHandler()) def on(self, event, handler=None, namespace=None): """Register an event handler. diff --git a/tests/test_server.py b/tests/test_server.py index 34ac61a2..31c33246 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -361,8 +361,13 @@ def test_disconnect_namespace(self, eio): def test_logger(self, eio): s = server.Server(logger=False) self.assertEqual(s.logger.getEffectiveLevel(), logging.ERROR) + s.logger.setLevel(logging.NOTSET) s = server.Server(logger=True) self.assertEqual(s.logger.getEffectiveLevel(), logging.INFO) + s.logger.setLevel(logging.WARNING) + s = server.Server(logger=True) + self.assertEqual(s.logger.getEffectiveLevel(), logging.WARNING) + s.logger.setLevel(logging.NOTSET) s = server.Server(logger='foo') self.assertEqual(s.logger, 'foo')