Skip to content

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

asokolsky
Copy link

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

@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)

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

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants