Skip to content

gh-145650: Add logging.{Formatter,Filter}.__repr__#145652

Open
JackDanger wants to merge 5 commits intopython:mainfrom
JackDanger:logging-repr
Open

gh-145650: Add logging.{Formatter,Filter}.__repr__#145652
JackDanger wants to merge 5 commits intopython:mainfrom
JackDanger:logging-repr

Conversation

@JackDanger
Copy link

@JackDanger JackDanger commented Mar 9, 2026

Add informative __repr__ implementations to logging.Formatter and logging.Filter, consistent with the existing repr style used by Handler and StreamHandler.

  • Formatter now displays its format string: <Formatter (%(message)s)>
  • Filter displays its filter name: <Filter (myapp)>

Closes #145650

@JackDanger JackDanger requested a review from vsajip as a code owner March 9, 2026 00:34
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 9, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@picnixz picnixz changed the title gh-145650: Add __repr__ to logging.Formatter and logging.Filter gh-145650: Add logging.{Formatter,Filter}.__repr__ Mar 9, 2026
return False
return (record.name[self.nlen] == ".")

def __repr__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the __repr__ after __init__ please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, great catch. Apologies for interactively rebasing a little fast and loose.

self.assertAlmostEqual(relativeCreated, offset_ns / 1e6, places=7)


def test_formatter_repr(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep only 1 blank lines between methods.

@@ -0,0 +1,3 @@
Add :func:`repr` support to :class:`http.client.HTTPConnection` and
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 unrelated.

@bedevere-app
Copy link

bedevere-app bot commented Mar 9, 2026

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

JackDanger and others added 2 commits March 8, 2026 17:58
…gRepr.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@JackDanger
Copy link
Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Mar 9, 2026

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz March 9, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logging.Formatter and logging.Filter are missing __repr__

2 participants