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.

Usage

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.

Licence

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.

Source Distribution

colorlog-0.4.tar.gz (2.6 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for colorlog-0.4.tar.gz
Algorithm Hash digest
SHA256 134267fb6c0fe83182fab2b0ec441da69471b41b4931a19846bdcd1821563806
MD5 ac1e6ba61476d92247de6aee0a773ec9
BLAKE2b-256 d9999ec9fb646790c64db9efbcbde1f714ad92407e74294301319305135ceafc

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