-
Notifications
You must be signed in to change notification settings - Fork 278
Description
Feature Description
Summary: Support NO_COLOR/FORCE_COLOR environment variables and improve color detection for Docker environments
Problem Statement:
When running crossbar in Docker containers or non-TTY environments, log output appears as plain uncolored text because the current color detection relies solely on sys.__stdout__.isatty(). This makes logs harder to read and doesn't follow modern CLI conventions for color control. Users have no way to force colors on or off via environment variables.
Proposed Solution:
Enhance the color auto-detection logic in _start_logging() to:
- Respect
NO_COLORenvironment variable to explicitly disable colors (per https://no-color.org/) - Respect
FORCE_COLORandCLICOLOR_FORCEenvironment variables to explicitly enable colors - Default to enabling colors when in auto mode
Use Cases
Use Case 1:
- Actor: DevOps engineer running crossbar in Docker
- Goal: View colored log output via
docker logsfor easier debugging - Example:
docker logs crossbar-containerdisplays colored output distinguishing log levels
Use Case 2:
- Actor: Developer with accessibility needs or specific terminal
- Goal: Disable colors that may not render correctly
- Example:
NO_COLOR=1 crossbar startruns without any ANSI color codes
Use Case 3:
- Actor: CI/CD pipeline operator
- Goal: Force colors in CI logs that support ANSI (GitHub Actions, GitLab CI)
- Example:
FORCE_COLOR=1 crossbar startensures colored output in CI logs
Example API/Usage
# Force colors on (Docker, CI/CD)
FORCE_COLOR=1 crossbar start
# Force colors off (accessibility, piping to file)
NO_COLOR=1 crossbar start
# Auto-detect (default) - now defaults to colors enabled
crossbar start# Current behavior in _start_logging():
if color == "auto":
if sys.__stdout__.isatty():
color = True
else:
color = False # Always disabled in Docker
# Proposed behavior:
if color == "auto":
if os.environ.get('NO_COLOR'):
color = False
elif os.environ.get('FORCE_COLOR') or os.environ.get('CLICOLOR_FORCE'):
color = True
elif sys.__stdout__.isatty():
color = True
else:
color = True # Default to colors enabledAlternatives Considered
Alternative 1: Only add TTY detection improvement
- Pros: Minimal change
- Cons: No user control via environment variables
Alternative 2: Add a new CLI flag --force-color
- Pros: Explicit control
- Cons: Doesn't follow industry standards, requires config changes
Why the proposed solution is better: Uses widely-adopted conventions (NO_COLOR, FORCE_COLOR, CLICOLOR_FORCE) that users already know from other tools. No new CLI flags needed, works with existing --color=auto option.
Impact Assessment
Breaking Changes: Minor - logs that previously had no color in non-TTY environments will now show colors by default. Users can set NO_COLOR=1 to restore previous behavior.
Affected Components:
- Core library (
src/crossbar/node/main.py) - API
- Documentation
- Tests
- CI/CD
Estimated Complexity: Low
Additional Context
Related Issues:
- None known
External References:
- https://no-color.org/ - NO_COLOR standard
- https://force-color.org/ - FORCE_COLOR convention
- CLICOLOR_FORCE - BSD/macOS convention also used by many tools
Checklist
- I have searched existing issues to avoid duplicates
- I have described the problem clearly
- I have provided use cases
- I have considered alternatives
- I have assessed impact and breaking changes