Beispiel #1
0
def stack_record():
    return factory(
        name="logger.testing",
        level=logging.INFO,
        fn="test_formatter",
        lno=4,
        msg="Test Message",
        args=(),
        exc_info=None,
        func=None,
        sinfo=make_stackinfo(),
    )
Beispiel #2
0
def exception_record():
    exc_info = Exception("Unhandled Exception").with_traceback(
        make_traceback())
    return factory(
        name="logger.testing",
        level=logging.ERROR,
        fn="test_formatter",
        lno=4,
        msg="Test Exception Message",
        args=(),
        exc_info=(type(exc_info), exc_info, exc_info.__traceback__),
        func=None,
        sinfo=None,
    )
Beispiel #3
0
async def test_factory_formats_msg() -> None:
    record = factory(
        name="logger.test",
        level=logging.INFO,
        fn="test_factory_retrun_type",
        lno=4,
        msg="Test Log %s",
        args=("extra",),
        exc_info=None,
        func=None,
        sinfo=None,
    )

    assert record.getMessage() == "Test Log extra"
Beispiel #4
0
async def test_factory_return_type() -> None:
    record = factory(
        name="logger.test",
        level=logging.INFO,
        fn="test_factory_retrun_type",
        lno=4,
        msg="Test Log",
        args=(),
        exc_info=None,
        func=None,
        sinfo=None,
    )

    assert isinstance(record, PydanticLogRecord)
    assert issubclass(PydanticLogRecord, logging.LogRecord)
Beispiel #5
0
async def test_factory_formats_msg_and_adds_pydantic_model() -> None:
    class LogModel(pydantic.BaseModel):
        _is_log_model = True
        foo: Optional[str]

    record = factory(
        name="logger.test",
        level=logging.INFO,
        fn="test_factory_retrun_type",
        lno=4,
        msg="Test Log %s",
        args=("extra", LogModel(foo="bar")),
        exc_info=None,
        func=None,
        sinfo=None,
    )

    assert record.getMessage() == "Test Log extra"
    assert len(record.pydantic_data) == 1
Beispiel #6
0
async def test_factory_adds_pydantic_models() -> None:
    class LogModel(pydantic.BaseModel):
        _is_log_model = True
        foo: Optional[str]

    record = factory(
        name="logger.test",
        level=logging.INFO,
        fn="test_factory_retrun_type",
        lno=4,
        msg="Test Log",
        args=(LogModel(foo="bar"),),
        exc_info=None,
        func=None,
        sinfo=None,
    )

    assert len(record.pydantic_data) == 1
    assert len(record.args) == 0
Beispiel #7
0
def extended_record():
    class FooLogModel(pydantic.BaseModel):
        _is_log_model = True
        foo: Optional[str]

    class FizLogModel(pydantic.BaseModel):
        _is_log_model = True
        fiz: Optional[str]

    return factory(
        name="logger.testing",
        level=logging.INFO,
        fn="test_formatter",
        lno=4,
        msg="Test Message",
        args=(FooLogModel(foo="bar"), FizLogModel(fiz="biz")),
        exc_info=None,
        func=None,
        sinfo=None,
    )