DEV.co
Open-Source Observability · borntyping

python-colorlog

python-colorlog is a lightweight Python library that adds colored output to the standard logging module, making log messages easier to read in terminals. It's a stable, mature project in maintenance mode with minimal dependencies (colorama on Windows) and broad platform support through official Linux distribution packages.

Source: GitHub — github.com/borntyping/python-colorlog
963
GitHub stars
99
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryborntyping/python-colorlog
Ownerborntyping
Primary languagePython
LicenseMIT — OSI-approved
Stars963
Forks99
Open issues1
Latest releasev6.10.1 (2025-10-16)
Last updated2025-10-16
Sourcehttps://github.com/borntyping/python-colorlog

What python-colorlog is

A pure-Python logging formatter that wraps Python's standard logging.Formatter to inject ANSI color escape codes based on log level. Supports custom colors, secondary log colors, multiple escape code combinations (bold, background, bright variants), and integrates with logging.config dictConfig and fileConfig. Requires Python 3.6+; colorama is auto-initialized on Windows.

Quickstart

Get the python-colorlog source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/borntyping/python-colorlog.gitcd python-colorlog# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

CLI tool development

Drop-in colored logging for command-line applications where visual hierarchy of log levels (DEBUG→INFO→WARNING→ERROR→CRITICAL) improves user experience and debugging speed.

Development and local debugging

Reduces cognitive load during development by color-coding log output; integrates seamlessly with existing Python logging configuration with minimal setup overhead.

Multi-level log monitoring

Secondary log colors allow simultaneous highlighting of different log record attributes (level name + message + source) for dense, readable terminal output during system monitoring.

Implementation considerations

  • Instantiate ColoredFormatter with format string and log_colors dict; no code changes to logger calls required—formatter injection point only.
  • Use reset=True (default) to automatically append color reset codes and prevent color bleed across subsequent log lines.
  • For non-TTY environments (files, CI/CD), detect output type and conditionally apply ColoredFormatter to avoid embedding ANSI codes in static logs.
  • secondary_log_colors provides multi-attribute coloring (e.g., different colors for level vs. message) without custom formatter subclassing.
  • Custom log levels (logging.addLevelName) are supported; add corresponding entries to log_colors dict for each custom level.

When to avoid it — and what to weigh

  • Structured/machine-readable logging required — colorlog outputs ANSI escape codes and is intended for human-readable terminal output. For JSON, syslog, or log aggregation pipelines, use structured logging libraries (e.g., structlog, jsonlog).
  • Production server logging to files — ANSI codes pollute file-based logs and log aggregation systems. Reserve colorlog for stderr/stdout handlers in development; use plain formatters for file handlers in production.
  • Non-terminal output (pipes, redirects, CI/CD logs) — ANSI color codes in piped or captured output create noise. Consider disabling colors when output is not a TTY, or use conditional formatter selection based on sys.stdout.isatty().
  • Windows console without colorama compatibility verification — While colorama is bundled and auto-initialized, Windows console ANSI support varies by OS version. Requires testing on target Windows editions before production deployment.

License & commercial use

MIT License (permissive, OSI-approved). Full text included in README: allows unrestricted use, modification, and distribution in source and binary form, provided copyright notice and license text are retained. No attribution required in binary distributions.

MIT License permits commercial use without restrictions. No licensing fees, no proprietary restrictions, no copyleft obligations. Safe for proprietary applications. No warranty provided (standard MIT disclaimer applies); review liability implications for mission-critical systems.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

No cryptography, network calls, or privilege escalation. ANSI escape code injection risk exists if log message content is untrusted and used in format strings with log_color variables—sanitize user-controlled log values before logging. colorlog itself does not sanitize or escape; it assumes logger calls are trusted. Standard logging module best practices apply (avoid logging sensitive data).

Alternatives to consider

structlog

Modern, feature-rich structured logging library with built-in color support, JSON output, and processor chains. Better for production systems and log aggregation; heavier weight than colorlog.

loguru

All-in-one logging replacement for Python with colors, file rotation, async handling, and simplified API. More opinionated and heavyweight; abandons stdlib logging in favor of custom logger.

colorama (standalone)

Lower-level cross-platform ANSI color library. Requires manual color management in log format strings; more control but less integration with logging module than colorlog.

Software development agency

Build on python-colorlog with DEV.co software developers

python-colorlog integrates in minutes with zero external dependencies. Evaluate it in your development workflow or discuss how to integrate structured logging at scale with our team.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

python-colorlog FAQ

Will colorlog pollute my log files with ANSI codes?
Only if you apply ColoredFormatter to file-writing handlers. Instantiate separate formatters: ColoredFormatter for StreamHandler(stderr), plain Formatter for FileHandler. Detect TTY with sys.stdout.isatty() if needed.
Does colorlog work on Windows?
Yes. colorama is auto-initialized on Windows import. Verify your Windows console supports ANSI codes (Windows 10 Build 1607+ or VT100 emulation enabled). Older Windows versions may not display colors.
Can I use custom colors beyond the predefined palette?
colorlog supports ANSI color names (black, red, green, etc.) and bright variants (light_*). Custom RGB colors are not supported; use escape code strings directly in log_colors if your terminal supports 256-color or true-color ANSI sequences, or use structlog for finer control.
Is colorlog actively maintained?
Yes, bugfixes are published (latest release 2025-10-16). However, the project is in 'maintenance mode': new features are unlikely due to backcompat constraints. Python 2 is no longer supported (v6 requires Python 3.6+).

Work with a software development agency

Adopting python-colorlog is usually one piece of a larger software development effort. As a software development agency, DEV.co provides software development services and web development expertise — pairing senior software developers and web developers with your team to design, build, and operate open-source observability software in production.

Ready to improve your CLI logging visibility?

python-colorlog integrates in minutes with zero external dependencies. Evaluate it in your development workflow or discuss how to integrate structured logging at scale with our team.