When making command line interfaces, it's often useful to colorize the output to emphasize salient pieces of information or otherwise enhance the user experience. Unfortunately it's quite cumbersome to add colorized outputs to Python log messages.
The ColorFormatter is a logging formatter that parses your log messages and adds color codes to the log messages.
The ColorStripper formatter is the inverse of the ColorFormatter. It strips the color information from your messages so that you can log to a file without it being full of color codes.
I'm on pypi!
$ pip install log_color
- Simple to use
- No external dependencies
- Compatibility with Python 3.7+, PyPy
- Fast! Compiled binaries are available for some systems!
LogColor honors the NO_COLOR environment variable.
This project uses uv for dependency management, command running, etc... install it:
$ curl -LsSf https://astral.sh/uv/install.sh | shIf you're on Linux or OSX, there is a Makefile with a number of helpful targets:
make check-typesRunmypystatic code analysis toolsmake format-codeRuns the ruff code formattermake check-codeValidates no code formatting errors or import sorting errors (check only, makes no changes)make wheelBuild Python.whlfile for distributionmake testRun the unittestsmake docsBuild the documentationmake freezeList all packages (and their version number) installed in the virtual environmentmake shellLaunch an interactive Python shell in the virtual environment contextmake cleanRemove any files that aren't part of the repo (build artifacts, test reports, etc...)make git-cleanRuns the gitfscktool, prunes the reflog, etc...
TIP: If you want to force a target to be re-evaluated (i.e. make env) run make with the -B flag to force
it to evaluate.
