-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Introduce qualname in extra parameters providing qualified name including classname. #128634
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Lib/logging/__init__.py
Outdated
@@ -1620,7 +1620,7 @@ def findCaller(self, stack_info=False, stacklevel=1): | |||
sinfo = sio.getvalue() | |||
if sinfo[-1] == '\n': | |||
sinfo = sinfo[:-1] | |||
return co.co_filename, f.f_lineno, co.co_name, sinfo | |||
return co.co_filename, f.f_lineno, co.co_name, sinfo, co.co_qualname |
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.
findCaller is documented, public API.
This breaks backward compatibility.
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.
Oh. Missed that.
So it cannot change the return type.
What could be the best alternative ?
Is introducing another method such as find_caller2 an option ?
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.
No. 3rd party code may override findCaller. Not calling it also breaks backward compatibility.
I think there is no way to add qualname in Logger without breaking backward compatibility.
You should create custom logger if you want qualname.
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.
This is an example that customize findCaller.
I think returning co.co_qualname
instead of co.co_name
is the best way to customize Logger.
Maybe, the Logger can have use_qualname
attribute.
logger = logging.getLogger(__name__)
logger.use_qualname = True # logger.findCaller() returns co_qualname instead of co_name
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
No description provided.