Log Colorizer is a simple command-line tool written in Go that reads log lines from standard input, detects keywords (such as ERROR, WARNING, INFO, etc.), and outputs colored log lines based on customizable mappings using 256-color ANSI escape codes.
If no custom mappings are specified, the tool uses the following defaults:
- ERROR: Bright red (
\033[38;5;196m) - WARNING: Bright yellow (
\033[38;5;226m) - INFO: Blue (
\033[38;5;33m)
- Go 1.12 or later
Clone the repository or copy the source code into a file named main.go. Then build the binary using:
go build -o colorize main.goThis will produce an executable called colorize.
You can also install the bin like so:
go installYou can pipe log output to colorize to see colored log lines. For example:
python -u myservice.py | ./colorizeOverride the default keyword-to-color mappings with the -mappings flag. The mappings should be provided as a comma-separated list of KEY:COLOR pairs, where COLOR is the 256-color code.
For example:
./colorize -mappings="ERROR:196,WARNING:226,INFO:33,DEBUG:82"In this example:
ERRORmessages will be displayed in bright red (color 196).WARNINGmessages will be displayed in bright yellow (color 226).INFOmessages will be displayed in blue (color 33).DEBUGmessages will be displayed in green (color 82).