Browse Source

Improved handling of logging

pull/5/head
Miguel Grinberg 10 years ago
parent
commit
4cb5151363
  1. 4
      socketio/server.py
  2. 5
      tests/test_server.py

4
socketio/server.py

@ -85,12 +85,14 @@ class Server(object):
if not isinstance(logger, bool):
self.logger = logger
else:
logging.basicConfig()
self.logger = logging.getLogger('socketio')
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.

5
tests/test_server.py

@ -361,8 +361,13 @@ class TestServer(unittest.TestCase):
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')

Loading…
Cancel
Save