Unexpected side-effect to calling LoggerFactory()
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start by reading structlog.stdlib.LoggerFactory and the logger class setup it performs; the issue provides a minimal reproduction using logging.getLogger. Check the relevant tests for logger factory behavior and reproduce whether constructing LoggerFactory changes the type returned by later calls. Done means the behavior is understood and covered by a regression test.
Written by the indexing model from the issue text.
Description
I'm using structlog package 19.2.0 but I've validated the behavior to be the same in version 19.1.0.
Instantiating LoggerFactory causes all subsequent calls to logging.getLogger to be of type
structlog.stdlib._FixedFindCallerLogger.
import logging
from structlog.stdlib import BoundLogger, LoggerFactory
from structlog import wrap_logger
print (logging.getLogger('foo'))
print(wrap_logger(logging.getLogger('bar'),
logger_factory=LoggerFactory(), wrapper_class=BoundLogger))
print(logging.getLogger('jazz')) # would expect this to be a logging.Logger instance
prints
logging.Logger object at 0x10169bf90>
<BoundLoggerLazyProxy(logger=<logging.Logger object at 0x101732990>, wrapper_class=<class 'structlog.stdlib.BoundLogger'>, processors=None, context_class=None, initial_values={'logger_factory': <structlog.stdlib.LoggerFactory object at 0x1017dbad0>}, logger_factory_args=())>
<structlog.stdlib._FixedFindCallerLogger object at 0x1017db8d0>
A minimal example (May not be appropriate usage. Only to illustrate)
import logging
from structlog.stdlib import LoggerFactory
print(logging.getLogger('foo'))
LoggerFactory()
print(logging.getLogger('jazz')) # would expect this to be a logging.Logger instance
prints
<logging.Logger object at 0x1085b9f90>
<structlog.stdlib._FixedFindCallerLogger object at 0x108650990>
This is a rather unexpected side-effect and causes client's code to return an unexpected type for logging.getLogger calls if structlog LoggerFactory is ever instantiated in a parent application. Is this something that can be addressed?
- Dominant language
- Python
- Stars
- 5k
- Forks
- 302
- Avg merge
- 17m
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hynek/structlog
-
bind_contextvars is not thread-safe?Possibly taken @nosmile99 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Transform examples in docs into included source filesPossibly taken @alexchen-sys claimed this 98 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
waiting for feedback
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Similar issues
-
resource-submission validation-passed
Difficulty 1/5 Under an hour Newbie friendliness 88/100
hesreallyhim/awesome-claude-code#3214 · 1 comment ·
Maintainers usually reply within 1 day
-
room-commons replace accepts an empty old string and silently prepends the new text to the pageOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
doobidoo/mcp-memory-service#1650 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ml-explore/mlx-lm#2002 ·
Maintainers usually reply within 2 days