Consistent use of error loggers (#2109)

* Consistent use of error loggers

* Fix tests
This commit is contained in:
ENT8R
2021-04-10 20:35:53 +02:00
committed by GitHub
parent ad97cac313
commit 53a571ec6c
7 changed files with 25 additions and 23 deletions

View File

@@ -276,7 +276,7 @@ def test_handle_request_with_nested_sanic_exception(app, monkeypatch, caplog):
assert response.status == 500
assert "Mock SanicException" in response.text
assert (
"sanic.root",
"sanic.error",
logging.ERROR,
f"Exception occurred while handling uri: 'http://127.0.0.1:{port}/'",
) in caplog.record_tuples

View File

@@ -113,9 +113,9 @@ def test_logging_pass_customer_logconfig():
def test_log_connection_lost(app, debug, monkeypatch):
""" Should not log Connection lost exception on non debug """
stream = StringIO()
root = logging.getLogger("sanic.root")
root.addHandler(logging.StreamHandler(stream))
monkeypatch.setattr(sanic.server, "logger", root)
error = logging.getLogger("sanic.error")
error.addHandler(logging.StreamHandler(stream))
monkeypatch.setattr(sanic.server, "error_logger", error)
@app.route("/conn_lost")
async def conn_lost(request):

View File

@@ -156,7 +156,7 @@ def test_middleware_response_raise_cancelled_error(app, caplog):
assert response.status == 503
assert (
"sanic.root",
"sanic.error",
logging.ERROR,
"Exception occurred while handling uri: 'http://127.0.0.1:42101/'",
) not in caplog.record_tuples
@@ -174,7 +174,7 @@ def test_middleware_response_raise_exception(app, caplog):
assert response.status == 404
# 404 errors are not logged
assert (
"sanic.root",
"sanic.error",
logging.ERROR,
"Exception occurred while handling uri: 'http://127.0.0.1:42101/'",
) not in caplog.record_tuples