Skip to content

fix: enable colored loguru output for terminal display#189

Merged
frostming merged 2 commits into
bubbuild:mainfrom
iodone:fix/loguru-colorize
Apr 29, 2026
Merged

fix: enable colored loguru output for terminal display#189
frostming merged 2 commits into
bubbuild: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 Outdated
Per review feedback, logger.remove() and logger.add(sys.stderr, colorize=True)
are always executed regardless of logfire availability, so move them before
the try block for cleaner control flow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@frostming frostming merged commit e50dc08 into bubbuild:main Apr 29, 2026
5 checks passed
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