Registry / observability / colorlog

colorlog

JSON →
library6.12.0pypypi✓ verified 10d ago

colorlog is a Python library that adds colors to the output of Python's standard logging module. It currently stands at version 6.10.1 and is in active maintenance, focusing on bug fixes and Python 3 compatibility, rather than major feature additions that might introduce breaking changes.

pip install colorlog
INSTALL
IMPORT
SIG · COLORLOG
C
colorlog
observabilitypythonv6.12.0
Install
1.6s avg
Import
36ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.038s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.034s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

basicConfig
from colorlog import basicConfig
import colorlog
ColoredFormatter
from colorlog import ColoredFormatter
StreamHandler
from colorlog import StreamHandler

This example demonstrates how to set up a basic logger with `colorlog.ColoredFormatter` to get colorized output. It defines custom colors for different logging levels and then logs messages at various severities. Alternatively, for a simpler setup, `colorlog.basicConfig()` can be used, which internally sets up a `ColoredFormatter` for the root logger.

import logging import colorlog # Configure a ColoredFormatter formatter = colorlog.ColoredFormatter( '%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s', datefmt=None, reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white' }, secondary_log_colors={}, style='%' ) # Get the root logger and set its level logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # Add a StreamHandler with the colored formatter handler = logging.StreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) # Example log messages logger.debug('This is a debug message') logger.info('This is an info message') logger.warning('This is a warning message') logger.error('This is an error message') logger.critical('This is a critical message')
Debug
Known issues
breakingcolorlog v6.x dropped support for Python 2 and Python versions older than 3.6. Users needing compatibility with older Python versions (e.g., Python 2.x or 3.5) must pin their dependency to `colorlog<5` or `colorlog<6` respectively.
fix
Upgrade Python to 3.6+ or pin `colorlog<5` for Python 2.x or `colorlog<6` for Python 3.5.
affects: >=6.0.0
breakingThe internal `TTYColoredFormatter` class was merged into `ColoredFormatter` in version 6.0.0-alpha.2. Direct references to `TTYColoredFormatter` will no longer work.
fix
Replace `TTYColoredFormatter` with `ColoredFormatter`.
affects: >=6.0.0a2
gotchaLogging output redirected to a file or a non-terminal environment will include raw ANSI escape codes, making the file unreadable unless processed by an ANSI-aware viewer. colorlog attempts to detect terminal capabilities but might fail in some setups.
fix
Ensure `ColoredFormatter` is only used with handlers outputting to terminals (e.g., `logging.StreamHandler`). For file logging, use a standard `logging.Formatter` or configure distinct handlers for terminal vs. file output. You can also use the `no_color` argument or the `NO_COLOR` environment variable to disable colors.
affects: All
gotchaThe `FORCE_COLOR` environment variable can override color detection, forcing colors even if `colorlog` thinks it's not a TTY. Conversely, the `NO_COLOR` environment variable (following the no-color.org standard) can disable colors.
fix
Be aware of these environment variables when troubleshooting unexpected color behavior in different environments.
affects: >=6.0.0a2 (NO_COLOR), >=6.6.0 (FORCE_COLOR)
deprecatedThe internal module `colorlog.colorlog` was renamed to `colorlog.formatter`. While direct import from `colorlog.colorlog` might still work for some time due to internal mechanisms, it is considered an internal detail and should not be relied upon.
fix
Always import `ColoredFormatter` directly from the top-level `colorlog` package (e.g., `from colorlog import ColoredFormatter`).
affects: >=6.3.0a1
Upgrade
Version history
6.12.0latest on PyPI · released Jul 23, 2026
Audit
Dependencies
coloramaoptionalProvides cross-platform ANSI color support, particularly on Windows. colorlog handles its initialization internally.
Agent activity
23 hits · last 30 days
node
20
Resources
colorlog — pip install colorlog · libregistry