Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AMAP ML SkillClaw LogColor

From Leeroopedia
Knowledge Sources
Domains Logging, Developer_Experience
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete colorized logging formatter for SkillClaw terminal output that applies ANSI color codes to log messages based on logger name, log level, and message content patterns.

Description

The SkillClawColorFormatter class extends `logging.Formatter` to colorize log output for terminal readability. It parses the standard `%(asctime)s | %(levelname)-8s | %(name)s | %(message)s` format using a regex (`LINE_PREFIX_RE`), extracts the level and logger name, then applies targeted colorization via `_colorize_message()`. Color rules include: logger-name-based INFO coloring (e.g., `skillclaw.api_server` → green, `skillclaw.trainer` → blue, `skillclaw.prm_scorer` → red), content-pattern matching (e.g., `[SkillManager]` → bold magenta, `[Trainer]` → bold blue, `[Scheduler]` → bold orange, POST 200 → bold magenta), and level-based fallbacks (WARNING → yellow, ERROR → red, DEBUG → magenta). The `setup_logging()` function configures the root logger with this formatter, enabling color only when stdout is a TTY.

Usage

Import and use when you need to:

  • Configure colorized logging for SkillClaw services: `setup_logging()`
  • Understand ANSI color mapping for SkillClaw components
  • Customize log colors for new components or message patterns
  • Debug which color rules apply to specific log messages

Code Reference

Source Location

  • Repository: SkillClaw
  • File: `skillclaw/log_color.py:L1-143`

Signature

class SkillClawColorFormatter(logging.Formatter):
    def __init__(self, fmt: str, *, use_color: bool):
        super().__init__(fmt=fmt)
        self.use_color = use_color

    def format(self, record: logging.LogRecord) -> str:
        """Render the log record, applying ANSI color if use_color is True
        and the message matches the expected pipe-delimited format."""

def setup_logging() -> None:
    """Configure root logger with SkillClawColorFormatter.
    Colors are enabled only when stdout is a TTY.
    Sets root level to INFO and clears existing handlers."""

# Color constants
ANSI_RESET = "\033[0m"
ANSI_BOLD = "\033[1m"
ANSI_BLUE = "\033[34m"
ANSI_CYAN = "\033[36m"
ANSI_GREEN = "\033[32m"
ANSI_YELLOW = "\033[33m"
ANSI_RED = "\033[31m"
ANSI_MAGENTA = "\033[35m"
ANSI_ORANGE = "\033[38;5;208m"

Import

from skillclaw.log_color import SkillClawColorFormatter, setup_logging

I/O Contract

Inputs

Name Type Required Description
fmt str Yes %(levelname)-8s | %(name)s | %(message)s"`)
use_color bool Yes Whether to apply ANSI color codes
record logging.LogRecord Yes (format) Standard log record to format

Outputs

Name Type Description
format returns str Colorized (or plain) formatted log line
setup_logging side effect None Configures root logger: clears handlers, adds StreamHandler with formatter, sets level to INFO

Usage Examples

Basic Setup

from skillclaw.log_color import setup_logging

setup_logging()
# All subsequent log output is colorized when stdout is a TTY

import logging
logger = logging.getLogger("skillclaw.api_server")
logger.info("Proxy started on port 30000")  # Green INFO
logger.warning("Rate limit approaching")    # Yellow WARNING
logger.error("Upstream connection failed")  # Red ERROR

Custom Formatter with Color

import logging
from skillclaw.log_color import SkillClawColorFormatter

handler = logging.StreamHandler()
fmt = "%(asctime)s | %(levelname)-8s | %(name)s | %(message)s"
handler.setFormatter(SkillClawColorFormatter(fmt, use_color=True))

logger = logging.getLogger("myapp")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

# Messages from known components get component-specific colors
logger.info("[SkillManager] Loading skill catalog")  # Bold magenta
logger.info("[Trainer] Starting epoch 1")             # Bold blue
logger.info("[Scheduler] Queue has 3 pending jobs")   # Bold orange

Component Color Mapping

from skillclaw.log_color import _info_color_for_logger

# Each logger name maps to a specific INFO color:
assert _info_color_for_logger("skillclaw.api_server")   == "\033[32m"  # green
assert _info_color_for_logger("skillclaw.trainer")      == "\033[34m"  # blue
assert _info_color_for_logger("skillclaw.launcher")     == "\033[36m"  # cyan
assert _info_color_for_logger("skillclaw.skill_manager") == "\033[35m" # magenta
assert _info_color_for_logger("skillclaw.prm_scorer")   == "\033[31m"  # red
assert _info_color_for_logger("httpx")                  == "\033[36m"  # cyan

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment