Skip to content

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