Skip to main content

Log formatting with colors!

Project description

colorlog.ColoredFormatter is a formatter for use with pythons logging module.

It allows colors to be placed in the format string, which is mostly useful when paired with a StreamHandler that is outputting to a terminal. This is accomplished by added a set of terminal color codes to the record before it is used to format the string.


ColoredFormatter requires at minumum a format string, and takes two options - reset and color_levels, which are shown using values equivalent to the defaults the following example.

from colorlog import ColoredFormatter

formatstring = "%(bg_level)s%(levelname)-8s%(reset)s %(blue)%(message)s"

levels = {
        'DEBUG':    'cyan',
        'INFO':     'green',
        'WARNING':  'yellow',
        'ERROR':    'red',
        'CRITICAL': 'red',

formatter = ColoredFormatter(formatstring, reset=True, color_levels=levels)

The formatter can then be used in a normal logging setup.


colorlog is distributed under the MIT Licence.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for colorlog, version 0.4
Filename, size File type Python version Upload date Hashes
Filename, size colorlog-0.4.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page