wimglenn / pytest-structlog

Structured logging assertions
MIT License
54 stars 6 forks source link

log captures events before processing, not after #34

Closed palfrey closed 3 months ago

palfrey commented 3 months ago

I've got a fairly extensive structlog config, including things that drop events that match particular patterns. I was trying to test this code with pytest-structlog, and it seems to not work? I'm guessing because of either structlog.configure being patched out (and so my config not getting applied) or the capture bits happening before my functions.

Any thoughts on this? I've worked around this at the moment with capsys and parsing of JSON logs, but would prefer a fixture here that can capture at the end of a processing queue.

wimglenn commented 3 months ago

In pytest-structlog 1.0 it is possible to keep pre-existing processors by using the new --structlog-evict CLI option, or by adding something like this in your pyproject.toml:

[tool.pytest.ini_options]
structlog_evict = ["TimeStamper", "JSONRender"]

Let me know if you have any troubles.