A while ago I did something similar, also for a log-file, with nawk
:
cat yourfile | nawk '
BEGIN {
arr["EXCEPTION"] = "0;31";
arr["\\[ERROR\\]"] = "1;31";
arr["\\[WARN\\]"] = "0;31";
arr["\\[INFO\\]"] = "1;34";
}
{
l = $0;
for (pattern in arr) {
gsub(pattern, "\033[" arr[pattern] "m&\033[0m", l);
}
print l;
}'
The configuration part should match your x => cx
style, you could also use tail -f
instead of cat
.
To be honest I don't think there's a tool for it as it's not that complex.