colorlog
Colored log output for Python's logging module — adds ANSI color codes to log levels without changing logging configuration patterns. colorlog features: ColoredFormatter drop-in for logging.Formatter, log_colors dict for per-level color config, %(log_color)s format specifier, %(reset)s to stop color, secondary_log_colors for additional format fields, LevelFormatter for per-level format strings, StreamHandler convenience wrapper, colorlog.getLogger() drop-in for logging.getLogger(), TTY detection (disables color when not a terminal), and reset= parameter. Zero-config upgrade to colored logging.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Pure logging formatter with no network calls. No security concerns. ANSI codes in log output are benign. Avoid logging sensitive data (secrets, PII) regardless of formatter used.
⚡ Reliability
Best When
Adding color to Python logging for development and debugging — colorlog is the minimal-change solution for colored log output without changing logging patterns.
Avoid When
Structured/JSON logs (use structlog), log shipping to aggregators, file-only logging, or when ANSI support is unreliable.
Use Cases
- • Agent colored logging setup — import colorlog; handler = colorlog.StreamHandler(); handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(levelname)s%(reset)s:%(name)s:%(message)s')); logger = colorlog.getLogger(__name__); logger.addHandler(handler) — colored logs; agent gets red ERROR, yellow WARNING, green INFO output in terminal
- • Agent custom color scheme — formatter = colorlog.ColoredFormatter('%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(name)s%(reset)s: %(message)s', log_colors={'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow,bold', 'ERROR': 'red,bold', 'CRITICAL': 'red,bg_white'}) — custom colors; agent configures precise color scheme per level
- • Agent basicConfig replacement — colorlog.basicConfig(level=logging.DEBUG, format='%(log_color)s%(levelname)s%(reset)s - %(message)s') — drop-in; agent replaces logging.basicConfig with colorlog.basicConfig for immediate colored output; minimal code change
- • Agent file + console split — console = colorlog.StreamHandler(); console.setFormatter(colorlog.ColoredFormatter()); file_handler = logging.FileHandler('app.log'); file_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')); logger.addHandler(console); logger.addHandler(file_handler) — dual handlers; agent logs colors to terminal and plain text to file simultaneously
- • Agent secondary colors — formatter = colorlog.ColoredFormatter('%(log_color)s%(levelname)s%(reset)s %(message_log_color)s%(message)s', secondary_log_colors={'message': {'ERROR': 'red', 'CRITICAL': 'red,bold'}}) — secondary colors; agent colors the message field separately from level field for ERROR/CRITICAL messages
Not For
- • Structured/JSON logging — colorlog is for human-readable terminal output; for machine-readable structured logs use python-json-logger or structlog
- • Log aggregation systems — ANSI codes corrupt log aggregators (Splunk, ELK); strip colors before shipping logs
- • File-only logging — color codes in file logs are noise; use plain logging.Formatter for file handlers
Interface
Authentication
No auth — logging formatter library.
Pricing
colorlog is MIT licensed. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ ANSI codes appear as raw text in non-TTY — colorlog 6.x auto-detects TTY and disables colors when output is not a terminal (piped/redirected); but some environments (Docker containers, CI systems) need FORCE_COLOR=1 env var or formatter(force_color=True) parameter; agent code in CI needing colors: set FORCE_COLOR=1
- ⚠ %(log_color)s must have matching %(reset)s — forgetting %(reset)s at end of colored section leaves terminal in colored state; subsequent non-colorlog output appears colored; agent format strings should always end with %(reset)s; pattern: '%(log_color)s%(levelname)s%(reset)s: %(message)s'
- ⚠ bold/bg_white color combinations use comma notation — colorlog.ColoredFormatter(log_colors={'ERROR': 'red,bold'}) combines color+style; colorlog.ColoredFormatter(log_colors={'CRITICAL': 'red,bold,bg_white'}) triple combination; agent code: look at colorlog.escape_codes for available codes; invalid code raises KeyError silently (uses empty string)
- ⚠ colorlog.getLogger() returns same instance as logging.getLogger() — they share the same logger registry; agent code calling colorlog.getLogger('app') and logging.getLogger('app') gets same logger; adding handler via colorlog.getLogger() affects same logger as logging configuration; not separate logging system
- ⚠ Multiple addHandler() calls create duplicate log lines — logger.addHandler(handler) is additive; calling setup code twice adds handler twice; agent code: check logger.handlers before adding; or use logging.config.dictConfig for declarative configuration; check: if not logger.handlers: logger.addHandler(handler)
- ⚠ propagate=True sends to root logger too — child loggers propagate to root logger by default; if root logger has a handler AND child logger has a handler, each log message appears twice; agent code: set propagate=False on named loggers with own handlers: logger.propagate = False
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for colorlog.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.