Skip to content

fix: enable colored loguru output for terminal display#189

Open
iodone wants to merge 1 commit intobubbuild:mainfrom
iodone:fix/loguru-colorize
Open

fix: enable colored loguru output for terminal display#189
iodone wants to merge 1 commit intobubbuild:mainfrom
iodone:fix/loguru-colorize

Conversation

@iodone
Copy link
Copy Markdown
Contributor

@iodone iodone commented Apr 27, 2026

Summary

  • Explicitly configure a colorize=True stderr sink for loguru so that log output is colored when displayed in a terminal
  • When logfire is available, the colorized stderr sink is added alongside the logfire handler

Problem

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 handlers
  • logger.add(sys.stderr, colorize=True) to ensure colored output in terminal display
  • When logfire is available, add logfire.loguru_handler() alongside the colorized sink

This ensures terminal display always has colored output while preserving logfire integration when available.

Test plan

  • Run uv run bub gateway and verify log output has ANSI colors in terminal
  • Verify logfire integration still works when logfire is installed
  • Verify graceful fallback when logfire is not installed

🤖 Generated with Claude Code

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>
Comment thread src/bub/__main__.py
Comment on lines +20 to +21
logger.remove()
logger.add(sys.stderr, colorize=True)
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.

If they are always executed, considering moving them outside and before the try block.

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