fix the logger and make it work (#1397)
* fix the logger and make it work * modify test_logging parameters and add a new unit test
This commit is contained in:
parent
e3a27c2cc4
commit
b63c06c75a
|
@ -6,7 +6,7 @@ LOGGING_CONFIG_DEFAULTS = dict(
|
||||||
version=1,
|
version=1,
|
||||||
disable_existing_loggers=False,
|
disable_existing_loggers=False,
|
||||||
loggers={
|
loggers={
|
||||||
"root": {"level": "INFO", "handlers": ["console"]},
|
"sanic.root": {"level": "INFO", "handlers": ["console"]},
|
||||||
"sanic.error": {
|
"sanic.error": {
|
||||||
"level": "INFO",
|
"level": "INFO",
|
||||||
"handlers": ["error_console"],
|
"handlers": ["error_console"],
|
||||||
|
|
|
@ -49,7 +49,7 @@ def test_logging_defaults():
|
||||||
reset_logging()
|
reset_logging()
|
||||||
app = Sanic("test_logging")
|
app = Sanic("test_logging")
|
||||||
|
|
||||||
for fmt in [h.formatter for h in logging.getLogger('root').handlers]:
|
for fmt in [h.formatter for h in logging.getLogger('sanic.root').handlers]:
|
||||||
assert fmt._fmt == LOGGING_CONFIG_DEFAULTS['formatters']['generic']['format']
|
assert fmt._fmt == LOGGING_CONFIG_DEFAULTS['formatters']['generic']['format']
|
||||||
|
|
||||||
for fmt in [h.formatter for h in logging.getLogger('sanic.error').handlers]:
|
for fmt in [h.formatter for h in logging.getLogger('sanic.error').handlers]:
|
||||||
|
@ -68,7 +68,7 @@ def test_logging_pass_customer_logconfig():
|
||||||
|
|
||||||
app = Sanic("test_logging", log_config=modified_config)
|
app = Sanic("test_logging", log_config=modified_config)
|
||||||
|
|
||||||
for fmt in [h.formatter for h in logging.getLogger('root').handlers]:
|
for fmt in [h.formatter for h in logging.getLogger('sanic.root').handlers]:
|
||||||
assert fmt._fmt == modified_config['formatters']['generic']['format']
|
assert fmt._fmt == modified_config['formatters']['generic']['format']
|
||||||
|
|
||||||
for fmt in [h.formatter for h in logging.getLogger('sanic.error').handlers]:
|
for fmt in [h.formatter for h in logging.getLogger('sanic.error').handlers]:
|
||||||
|
@ -82,7 +82,7 @@ def test_logging_pass_customer_logconfig():
|
||||||
def test_log_connection_lost(app, debug, monkeypatch):
|
def test_log_connection_lost(app, debug, monkeypatch):
|
||||||
""" Should not log Connection lost exception on non debug """
|
""" Should not log Connection lost exception on non debug """
|
||||||
stream = StringIO()
|
stream = StringIO()
|
||||||
root = logging.getLogger('root')
|
root = logging.getLogger('sanic.root')
|
||||||
root.addHandler(logging.StreamHandler(stream))
|
root.addHandler(logging.StreamHandler(stream))
|
||||||
monkeypatch.setattr(sanic.server, 'logger', root)
|
monkeypatch.setattr(sanic.server, 'logger', root)
|
||||||
|
|
||||||
|
@ -102,3 +102,15 @@ def test_log_connection_lost(app, debug, monkeypatch):
|
||||||
assert 'Connection lost before response written @' in log
|
assert 'Connection lost before response written @' in log
|
||||||
else:
|
else:
|
||||||
assert 'Connection lost before response written @' not in log
|
assert 'Connection lost before response written @' not in log
|
||||||
|
|
||||||
|
|
||||||
|
def test_logging_modified_root_logger_config():
|
||||||
|
reset_logging()
|
||||||
|
|
||||||
|
modified_config = LOGGING_CONFIG_DEFAULTS
|
||||||
|
modified_config['loggers']['sanic.root']['level'] = 'DEBUG'
|
||||||
|
|
||||||
|
app = Sanic("test_logging", log_config=modified_config)
|
||||||
|
|
||||||
|
assert logging.getLogger('sanic.root').getEffectiveLevel() == logging.DEBUG
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user