-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-115233: Fix currentframe to get the frame of original caller #115241
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
Conversation
Unit test is passing, I will try to check, but what's the issue here, we
should try to look for the most deepest frame possible so that we don't
miss the exact caller.
…On Sun, 11 Feb, 2024, 00:16 Vinay Sajip, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Lib/logging/__init__.py
<#115241 (comment)>:
> @@ -164,7 +164,7 @@ def addLevelName(level, levelName):
_nameToLevel[levelName] = level
if hasattr(sys, "_getframe"):
- currentframe = lambda: sys._getframe(1)
+ currentframe = lambda: sys._getframe(3)
I can understand that you have to add extra frames to allow for code in
the LoggerAdapter, but what about code that doesn't use an adapter? What
changed in 3.11 and later to cause the related issue?
—
Reply to this email directly, view it on GitHub
<#115241 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHPPFO6SG4UQNWZ33SI4CYDYS66BJAVCNFSM6AAAAABDCVP5HOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNZTHEZDGOJSGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I deleted my comment because just after I posted it, I remembered the earlier issue whose fix was in this area. I think the test should include calls both via the adapter and not, to ensure that the correct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it fixes LoggerAdapter, it breaks Logger.
I think that the proper fix should add the stacklevel
parameter in LoggerAdapter._log()
and call self.logger._log()
with the proper value of stacklevel
. You need also to balance stacklevel for LoggerAdapter.log()
and other logging methods. The simplest way is to move some code from LoggerAdapter.log()
to LoggerAdapter._log()
and use ._log()
instead of log()
in other methods.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Hi @serhiy-storchaka , I have made the requested changes; please review again, but it has changed the way records are getting pushed in the handler, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test for formatting funcName
in Logger
: test_find_caller_with_stacklevel
. Just add a similar test, but with LoggerAdapter
(in class LoggerAdapterTest
).
Lib/logging/__init__.py
Outdated
""" | ||
Delegate a debug call to the underlying logger. | ||
""" | ||
self.log(DEBUG, msg, *args, **kwargs) | ||
self._log(DEBUG, msg, *args, stacklevel=stacklevel + 1, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be simpler to just pass **kwargs
, as in Logger
methods, and just do a double correction in _log()
.
Also, it will be more efficient to pass args
instead of *args
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please check
Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
sure, let me explore, I will add it, btw, I am still figuring out why below is failing
|
An extra comma somewhere making something a tuple when that's not intended? |
Hi @vsajip this is expected now as after restructuring, every adapter is going to hit _log and it will update the (extra context) args @serhiy-storchaka previously, it was calling
|
It was surprising that new tests are passed with the unmodified code. It means that either the code was not broken, or that the new tests do not work as intended. I played with the code yesterday, and came to conclusion that both are true. The new tests did not test LoggerAdapter, and the code worked as intended while we use standard classes, the problem was in the example. So I created a new PR #115325 which includes the fixed example and fixed tests. |
Okay, got you. |
should i close my PR? @serhiy-storchaka |
Yes, I think nothing to do here. This issue was not as it seemed at first glance. |
Uh oh!
There was an error while loading. Please reload this page.