A simple python logging formater to add ANSI color codes depending on log level for a prettier output in console.
|
7 years ago | |
---|---|---|
.gitignore | 7 years ago | |
README.md | 7 years ago | |
__init__.py | 7 years ago |
Simple logging formatter adding color codes to messages depending on log level. It's easy but I was tired of rewriting it on each project.
Use it like this:
from pycolog import ColoredFormatter
# You can use it as a regular formatter, specifying fmt as you need.
log_formatter = ColoredFormatter("%(asctime)s: %(message)s"
# You also may chose a custom color set. Any level not specified will be
# printed with regular color.
log_formatter2 = ColoredFormatter( "%(message)s",
colors = {
"WARNING" : ColoredFormatter.BLUE,
"ERROR" : ColoredFormatter.YELLOW,
} )
The code is really easy. Take a look if you want more details (all available colors and such).