Debian Codegraph @

testing/mozbase/mozlog/tests/conftest.py

raw
1 import pytest
2 from mozlog.formatters import ErrorSummaryFormatter, MachFormatter
3 from mozlog.handlers import StreamHandler
4 from mozlog.structuredlog import StructuredLogger
5 from six import StringIO
6
7
8 @pytest.fixture
9 def get_logger():
10 # Ensure a new state instance is created for each test function.
11 StructuredLogger._logger_states = {}
12 formatters = {
13 "mach": MachFormatter,
14 "errorsummary": ErrorSummaryFormatter,
15 }
16
17 def inner(name, **fmt_args):
18 buf = StringIO()
19 fmt = formatters[name](**fmt_args)
20 logger = StructuredLogger("test_logger")
21 logger.add_handler(StreamHandler(buf, fmt))
22 return logger
23
24 return inner