From 918e2ba8d06ca0aff63cc2354539274a6a1f6105 Mon Sep 17 00:00:00 2001 From: zyguan Date: Mon, 24 Jul 2017 11:53:11 +0800 Subject: [PATCH 1/2] Revert "fix #752" This reverts commit 599fbcee6e1e427829a9f03de7f7aad2ee67ac22. --- sanic/app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index f1e8be7e..f0ccad86 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -33,9 +33,7 @@ class Sanic: logging.config.dictConfig(log_config) # Only set up a default log handler if the # end-user application didn't set anything up. - if not (logging.root.handlers and - log.level == logging.NOTSET and - log_config): + if not logging.root.handlers and log.level == logging.NOTSET: formatter = logging.Formatter( "%(asctime)s: %(levelname)s: %(message)s") handler = logging.StreamHandler() From da91b16244958b862b95077815e6a7d39b2d019b Mon Sep 17 00:00:00 2001 From: zyguan Date: Mon, 24 Jul 2017 18:21:15 +0800 Subject: [PATCH 2/2] add tests --- tests/test_logging.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_logging.py b/tests/test_logging.py index fc26ca93..d6911d86 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -1,5 +1,7 @@ -import asyncio import uuid +from importlib import reload + +from sanic.config import LOGGING from sanic.response import text from sanic import Sanic from io import StringIO @@ -10,6 +12,11 @@ function: %(funcName)s(); \ message: %(message)s''' +def reset_logging(): + logging.shutdown() + reload(logging) + + def test_log(): log_stream = StringIO() for handler in logging.root.handlers[:]: @@ -32,5 +39,19 @@ def test_log(): log_text = log_stream.getvalue() assert rand_string in log_text + +def test_default_log_fmt(): + + reset_logging() + Sanic() + for fmt in [h.formatter for h in logging.getLogger('sanic').handlers]: + assert fmt._fmt == LOGGING['formatters']['simple']['format'] + + reset_logging() + Sanic(log_config=None) + for fmt in [h.formatter for h in logging.getLogger('sanic').handlers]: + assert fmt._fmt == "%(asctime)s: %(levelname)s: %(message)s" + + if __name__ == "__main__": test_log()