Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore frames in _FixedFindCallerLogger #602

Open
wochinge opened this issue Feb 28, 2024 · 1 comment
Open

Ignore frames in _FixedFindCallerLogger #602

wochinge opened this issue Feb 28, 2024 · 1 comment

Comments

@wochinge
Copy link

Hi y'all,

I'm currently writing a wrapper for the standard logger to make the log calls look a certain way.

The problem is that my wrapper ends up in the stack trace when adding information like line number / calling module to the log.

The standard library allows fixing this by increasing the stack level:

logger = logging.getLogger()
logger.info("Hi, stacklevel=2)

Structlog does something similar when providing the parameter "ignore_frame_names" for the structlog.stdlib.LoggerFactory. Problem is that the LoggerFactory sets a LoggerClass which ignores the stacklevel number and which is not parametrizable.

it would be great if the ignored frames could be changed without overriding stuff or (probably the better solution) the stacklevel param would be passed on and handled correctly.

Happy to contribute once we agree on a solution!

@wochinge wochinge changed the title Ignore traces in Ignore frames in _FixedFindCallerLogger Feb 28, 2024
@hynek
Copy link
Owner

hynek commented Mar 5, 2024

Hmm, this is once again very awkward because we have to intercept things that stdlib is doing. :/

I would say that CallsiteParameterAdder would be the cleaner choice but I presume you need deeper stdlib support?

If I see it correctly, our loggers call it from

def findCaller(
self, stack_info: bool = False
) -> tuple[str, int, str, str | None]:
"""
Calls :meth:`logging.Logger.findCaller` with unmodified arguments.
"""
return self._logger.findCaller(stack_info=stack_info)

I suppose we could add a stacklevel argument – the question is how to signal it from the outside. Starting to interpret stacklevel in all loggers would be a breaking change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants