Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: make rich logger optional #182

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

Draft
asokolsky wants to merge 1 commit into fastapi:main
base: main
Choose a base branch
Loading
from asokolsky:support-non-rich-logging

Conversation

Copy link

@asokolsky asokolsky commented Jul 11, 2025

Do NOT use rich logger when fastapi cli output is redirected or piped.
For the output to a terminal the behavior is unchanged.

yedpodtrzitko reacted with thumbs up emoji
@asokolsky asokolsky marked this pull request as draft July 11, 2025 00:28
console=console,
)
rich_handler.setFormatter(logging.Formatter("%(message)s"))
logger.addHandler(rich_handler)
Copy link

@YuriiMotov YuriiMotov Jul 12, 2025

Choose a reason for hiding this comment

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

Why did you remove logger.addHandler(rich_handler)?

Copy link
Author

@asokolsky asokolsky Jul 13, 2025

Choose a reason for hiding this comment

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

I removed rich handler because, as a part of https://github.com/Textualize/rich it makes assumptions about output being console. In no way does this compromise logging capabilities when output is redirected to file.

Logging handlers and formatters can be set by the outside code, e.g. the way you set logging config for uvicorn here: https://github.com/fastapi/fastapi-cli/blob/main/src/fastapi_cli/cli.py#L180

Here is how I set logging config via a single yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@YuriiMotov YuriiMotov YuriiMotov left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /