Repository navigation
Let the logfire-api shim's StructlogProcessor, LogfireLoggingHandler and loguru_handler be used without logfire - #2786
Merged
alexmojaki merged 1 commit intoNov 12, 2026
Conversation
…and loguru_handler be used without logfire Without logfire installed, the shim's StructlogProcessor wasn't callable, LogfireLoggingHandler wasn't a logging.Handler, and loguru_handler() returned an empty dict with no sink, so the documented setups for structlog, stdlib logging and Loguru raised as soon as they were configured or used.
PR overviewNo security issues were found in this pull request. Reviews
|
alexmojaki
enabled auto-merge
November 12, 2026 10:15
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A library that depends only on
logfire-apiand wires up logging the way the integration docs show breaks whenlogfireisn't installed. The three logging integrations in the shim are bare classes/functions that don't satisfy the interface the logging library expects:With
logfireinstalled all three work, so the shim is the only place this fails, which is exactly the case it exists for.Changes in
logfire-api/logfire_api/__init__.py:StructlogProcessor.__call__(logger, name, event_dict)returnsevent_dictunchanged, like the real processor does after logging.LogfireLoggingHandlersubclasseslogging.NullHandlerand accepts the real handler'slevelargument (other arguments are still ignored), so it can be added to loggers and passed tobasicConfig/dictConfigand simply drops records.loguru_handler()returns a sink that discards messages plus the same'format': '{message}'the real one returns, sologger.add(**loguru_handler())andlogger.configure(handlers=[...])work.test_runtimeintests/test_logfire_api.pynow actually uses each of these (adds the handler to a stdlib logger and logs, adds the Loguru handler and logs, calls the structlog processor) instead of only constructing them, for both the shim and the real module.Testing:
uv run pytest tests/test_logfire_api.py: onmainthe new assertions fail forwithout_logfire(isinstance(LogfireLoggingHandler(), logging.Handler)is False); with this change: 3 passed, 1 skipped.ruff format --check,ruff checkandpyrighton both touched files: clean.