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, 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. The codes are mostly in the format fg_{colorname} or bg_{colorname} (foreground and background colors). Also provided are bold (for bold output), reset (to reset all formatting), and fg_level / bg_level, which return the color associated with the records level (which is defined by either DEFAULT_COLOR_LEVELS or a user-provided dict (color_levels) containing a mapping of level names to color names.

The colors names are black, red, green, yellow, blue, purple, cyan and white.

A reset code is implictly appended to all messages unless reset == False.

A usage example, also showing the default color mapping:

>>> 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',
        }
>>> ColoredFormatter(formatstring, reset=True, color_levels=levels)

Project details


Download files

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

Source Distribution

colorlog-0.1.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file colorlog-0.1.tar.gz.

File metadata

  • Download URL: colorlog-0.1.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for colorlog-0.1.tar.gz
Algorithm Hash digest
SHA256 9803298286e678abe4c4ee30e5bfdeb55e7e54ff8312f3c923ed2447ccbf7cf2
MD5 11ba8cc6a398b505554209ce06600077
BLAKE2b-256 cb1b025d02a294229985e46204fc5d6ada5fbd4881ef08a9a28bfcb055047f4a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page