Skip to content

Commit

Permalink
test(logging): ensure setup's formatter is handled
Browse files Browse the repository at this point in the history
Test that the user can set a custom formatter in `clapper.logging.setup`
  • Loading branch information
Yannick-Dayer committed Sep 26, 2024
1 parent 49d3c86 commit 6938626
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6938626

Please sign in to comment.