fix: enable colored loguru output for terminal display#189
Open
iodone wants to merge 1 commit intobubbuild:mainfrom
Open
fix: enable colored loguru output for terminal display#189iodone wants to merge 1 commit intobubbuild:mainfrom
iodone wants to merge 1 commit intobubbuild:mainfrom
Conversation
loguru's default handler does not emit ANSI color codes in non-TTY or certain terminal environments. Explicitly configure a stderr sink with colorize=True so that log output is colored regardless of the runtime context. When logfire is available, the colorized stderr sink is added alongside the logfire handler so both destinations receive output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
frostming
reviewed
Apr 27, 2026
Comment on lines
+20
to
+21
| logger.remove() | ||
| logger.add(sys.stderr, colorize=True) |
Collaborator
There was a problem hiding this comment.
If they are always executed, considering moving them outside and before the try block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
colorize=Truestderr sink for loguru so that log output is colored when displayed in a terminalProblem
loguru's default handler does not emit ANSI color codes in certain terminal environments (e.g., when running through subprocess wrappers or non-TTY stdin contexts). This causes log output to lose color formatting.
Fix
In
_instrument_bub(), explicitly configure loguru with:logger.remove()to clear default handlerslogger.add(sys.stderr, colorize=True)to ensure colored output in terminal displaylogfire.loguru_handler()alongside the colorized sinkThis ensures terminal display always has colored output while preserving logfire integration when available.
Test plan
uv run bub gatewayand verify log output has ANSI colors in terminal🤖 Generated with Claude Code