Log formatting with colors!
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 (implictly add a reset code at the end of message strings, defaults to true) and color_levels (a mapping of record level names to color names, defaults to colorlog.DEFAULT_COLOR_LEVELS).
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.
Codes
The following values are made availible for use in the format string:
fg_{colorname}, bg_{colorname}: Foreground and background colors. The colors names are black, red, green, yellow, blue, purple, cyan and white.
bold: Bold output.
reset: Clear all formatting (both foreground and background colors).
fg_level, bg_level: Return the color associated with the records level (from color_levels).
Licence
colorlog is distributed under the MIT Licence.
Metadata
Release files for colorlog 0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| colorlog-0.6.tar.gz | 3.2 kB | Without provenance | Details for colorlog-0.6.tar.gz |
Release files / colorlog-0.6.tar.gz
| Download URL | colorlog-0.6.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa70776fdf3384b1d832d818d3474a1d4183b44b12c4a052219f0723d3d1b9f3
|
|
BLAKE2b-256 checksum How to use checksums |
8f69bf7107a8f21db9c6031c2ebfe7ac2474b35dc3150b74a068d2635f2127ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for colorlog 0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.