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

Introduce qualname in extra parameters providing qualified name including classname. #128634

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

NN---
Copy link

@NN--- NN--- commented Jan 8, 2025

No description provided.

Copy link

cpython-cla-bot bot commented Jan 8, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 8, 2025

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 skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Jan 8, 2025

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 skip news label instead.

@@ -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
Copy link
Member

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.

Copy link
Author

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 ?

Copy link
Member

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.

Copy link
Member

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.

https://github.com/hynek/structlog/blob/b488a8bf589a01aabc41e3bf8df81a9848cd426c/src/structlog/stdlib.py#L107

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

@bedevere-app
Copy link

bedevere-app bot commented Jan 9, 2025

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 skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Jan 9, 2025

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 skip news label instead.

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

Successfully merging this pull request may close these issues.

2 participants