Coloredlogs: Colored Terminal Output for Python's Logging Module

15.0.1 · active · verified Sat Mar 28

coloredlogs is a Python library that enhances the default logging output by adding color formatting to log messages. It provides a simple way to make log messages more visually distinguishable, making it easier to read and interpret log output, especially when working in a terminal or command-line environment. The current version is 15.0.1. It is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `coloredlogs` and the standard `logging` module, create a logger, and then apply colored output using `coloredlogs.install()` to a specific logger with a 'DEBUG' level. Log messages at different severity levels will then be displayed with corresponding colors in the terminal.

import coloredlogs, logging

# Create a logger object. By default, coloredlogs.install()
# will apply to the root logger if no logger is specified.
logger = logging.getLogger(__name__)

# Install coloredlogs on the logger.
# You can also pass level='INFO' or other levels.
coloredlogs.install(level='DEBUG', logger=logger)

# Some examples of 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')

view raw JSON →