Skip to content

Logger has [transformers] prefix in non-verbose mode#45316

Merged
zucchini-nlp merged 6 commits intohuggingface:mainfrom
zucchini-nlp:log-lib-name
Apr 10, 2026
Merged

Logger has [transformers] prefix in non-verbose mode#45316
zucchini-nlp merged 6 commits intohuggingface:mainfrom
zucchini-nlp:log-lib-name

Conversation

@zucchini-nlp
Copy link
Copy Markdown
Member

What does this PR do?

As per title and seems like there are no objections. Also added some colors in verbose logging

cc @tarekziade @tomaarsen @yonigozlan if you have better ideas to style this (just tagging since you reacted ➕ )

This is how it looks like by default:
image

This is how it looks like when verbose:
image

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment thread src/transformers/utils/logging.py Outdated
if os.getenv("TRANSFORMERS_VERBOSITY", None) == "detail":
formatter = logging.Formatter("[%(levelname)s|%(pathname)s:%(lineno)s] %(asctime)s >> %(message)s")
_default_handler.setFormatter(formatter)
formatter = ColoredVerboseFormatter()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When logging happens in CI (see env flag below) we can probably keep a simple non-colored formatter to avoid weird console content in some UI

@tomaarsen
Copy link
Copy Markdown
Member

I have a bit of a personal dislike for colored logs, but that might just be me. I'll give this a better review on Friday. Please ping me if I forget. I'd like to check what happens with the Sentence Transformers logs that also rely on transformers.utils.logging.

  • Tom Aarsen

@zucchini-nlp
Copy link
Copy Markdown
Member Author

Oh, I will revert the coloring. @tarekziade found that there's a no-color standard since 2017. Sure, will ping in Friday, maybe we could infer the "lib-name" in that case

Copy link
Copy Markdown
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Looks good! Agree that no color is better. Thanks @zucchini-nlp

@zucchini-nlp
Copy link
Copy Markdown
Member Author

Checked with ST and seems like the formatting isn't applied to logged messages from other libraries. Ig by the time ST imports the logger, we have already configured the handler and added it to root library's logger. Since we don't configure it second time, the formatter never gets added after that, even when the root library is different

But we can be more careful and check library name when formattting. I'll push that and merge @tomaarsen

@zucchini-nlp zucchini-nlp enabled auto-merge April 10, 2026 09:07
@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45316&sha=e2c345

@zucchini-nlp zucchini-nlp added this pull request to the merge queue Apr 10, 2026
Merged via the queue into huggingface:main with commit d13b44b Apr 10, 2026
28 checks passed
@zucchini-nlp zucchini-nlp deleted the log-lib-name branch April 10, 2026 09:57
@tomaarsen
Copy link
Copy Markdown
Member

Will give this a try on Monday! My apologies.

  • Tom Aarsen

@tomaarsen
Copy link
Copy Markdown
Member

So far it seems to work okay. The transformers logs are nicely prefixed, and there's no prefixing for Sentence Transformers in my tests. It seems to be because there's already a default handler configured (i.e. the one for transformers itself). An improvement, at least!

  • Tom Aarsen

@zucchini-nlp
Copy link
Copy Markdown
Member Author

Yep, and if there is somehow no default handler in other 3rd party libs, they will see their own lib-name prefixed 😄 I added a line to check the name first

sirzechs66 pushed a commit to sirzechs66/transformers that referenced this pull request Apr 18, 2026
…5316)

* .

* wait

* no color

* oops

* lib name is not hardcoded anymore
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.

5 participants