Skip to content

Commit

Permalink
Add tests to assert how logger_name is attached to records
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamalama committed Apr 25, 2024
1 parent 4fbb011 commit 47c008a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/core/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@ class = dockerflow.logging.MozlogHandler
assert logger.handlers[0].logger_name == "tests"
assert isinstance(logger.handlers[0].formatter, MozlogFormatter)

def test_set_logger_name_through_handler(caplog):
handler = MozlogHandler(name="logger_name_handler")
logger = logging.getLogger("test")
logger.addHandler(handler)
logger.warning("hey")
[record] = caplog.records
record.logger_name = "logger_name_handler"

def test_set_logger_name_through_formatter(caplog):
handler = logging.StreamHandler()
formatter = MozlogFormatter(logger_name="logger_name_formatter")
handler.setFormatter(formatter)

logger = logging.getLogger("test")
logger.addHandler(handler)

logger.warning("hey")
[record] = caplog.records
record.logger_name = "logger_name_formatter"

def test_handler_precedence_logger_name(caplog):
handler = MozlogHandler(name="logger_name_handler")
formatter = MozlogFormatter(logger_name="logger_name_formatter")
handler.setFormatter(formatter)

logger = logging.getLogger("test")
logger.addHandler(handler)

logger.warning("hey")
[record] = caplog.records
record.logger_name = "logger_name_handler"

def test_basic_operation(caplog, handler, formatter):
"""Ensure log formatter contains all the expected fields and values"""
Expand Down

0 comments on commit 47c008a

Please sign in to comment.