4 ms·
I wrote a Python script (called synesthesia)[1] that'll colorize input based on regex matches, and any matched text will be the same color for the same content.
by cromo 12y ago
I wrote a Python script (called synesthesia)[1] that'll colorize input based on regex matches, and any matched text will be the same color for the same content.
The use case that drove its development was needing to keep track of UUIDs across multiple logs - and grep --color will colorize its matches, but not differentiate between ones that have different content. With this, I could watch both logs as data was passed from one to the other and keep track of e.g. the orange one.
I also thought it would be nice to be able to use patterns from logstash's grok, so I wrote grokpat[2] to find patterns for me. A lot of grok's patterns use atomic groups, which aren't available in Python 2, so I wrote redi[3] to convert them from grok's syntax to Python compatible syntax.
So I can now colorize logs easily as follows:
tail -F program.log | synesthesia "$(redi "$(grokpat uuid)")"
[1] https://github.com/cromo/synesthesia https://github.com/cromo/synesthesia
[2] https://github.com/cromo/grokpat https://github.com/cromo/grokpat
[3] https://github.com/cromo/redi https://github.com/cromo/redi
- philsnow 12y agothat's way better than my alternative which was a bash function: function hl() { local R='' while [ $# -gt 0 ]; do R="$R|$1" shift done env GREP_COLORS="mt=38;5;$((RANDOM%256))" egrep --color=always $R } thanks