log.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Terminal output utilities: colors and structured logging.
  3. Single source of truth for Colors and log_* functions
  4. used across all Trellis scripts.
  5. """
  6. from __future__ import annotations
  7. class Colors:
  8. """ANSI color codes for terminal output."""
  9. RED = "\033[0;31m"
  10. GREEN = "\033[0;32m"
  11. YELLOW = "\033[1;33m"
  12. BLUE = "\033[0;34m"
  13. CYAN = "\033[0;36m"
  14. DIM = "\033[2m"
  15. NC = "\033[0m" # No Color / Reset
  16. def colored(text: str, color: str) -> str:
  17. """Apply ANSI color to text."""
  18. return f"{color}{text}{Colors.NC}"
  19. def log_info(msg: str) -> None:
  20. """Print info-level message with [INFO] prefix."""
  21. print(f"{Colors.BLUE}[INFO]{Colors.NC} {msg}")
  22. def log_success(msg: str) -> None:
  23. """Print success message with [SUCCESS] prefix."""
  24. print(f"{Colors.GREEN}[SUCCESS]{Colors.NC} {msg}")
  25. def log_warn(msg: str) -> None:
  26. """Print warning message with [WARN] prefix."""
  27. print(f"{Colors.YELLOW}[WARN]{Colors.NC} {msg}")
  28. def log_error(msg: str) -> None:
  29. """Print error message with [ERROR] prefix."""
  30. print(f"{Colors.RED}[ERROR]{Colors.NC} {msg}")