From 69386264c95ab028e2647bbc9fb2208620000e3b Mon Sep 17 00:00:00 2001 From: Yannick DAYER Date: Thu, 26 Sep 2024 15:11:30 +0200 Subject: [PATCH] test(logging): ensure setup's formatter is handled Test that the user can set a custom formatter in `clapper.logging.setup` --- tests/test_logging.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_logging.py b/tests/test_logging.py index 6d4a4e9..ed6daed 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -35,6 +35,32 @@ def test_logger_setup(): assert hi.getvalue() == "warning message\nerror message\n" +def test_logger_setup_formatter(): + log_output = io.StringIO() + + custom_formatter = logging.Formatter(fmt="custom {message:s}", style="{") + + logger = clapper.logging.setup( + "awesome.logger", + low_level_stream=log_output, + high_level_stream=log_output, + formatter=custom_formatter, + ) + logger.setLevel(logging.DEBUG) + + logger.debug("debug message") + logger.info("info message") + logger.warning("warning message") + logger.error("error message") + + assert log_output.getvalue() == ( + "custom debug message\n" + "custom info message\n" + "custom warning message\n" + "custom error message\n" + ) + + def test_logger_click_no_v(): lo = io.StringIO() hi = io.StringIO()