Knut
Knut

Reputation: 441

colorful console output by unix pipe filter

while examining the console output and logging messages of different software it is sometimes difficult to keep the overview. It would be much easier to make the output colorful and highlight the text phrases which are currently important.

Is there a program for Linux/UNIX shell which could be used as a filter by utilizing unix pipes to make the console output colorful according to predefined patterns and colors?

p.ex. pattern definition:

INFO=green
WARN=yellow
ERROR=red
\d+=lightgreen

to highlight the severity of the message and also numbers.

usage:

$ chatty_software | color_filter
11:41:21.000 [green:INFO]  runtime.busevents - SensorA state updated to [lightgreen:17]
11:41:21.004 [green:INFO]  runtime.busevents - SensorB state updated to [lightgreen:20]

original output:

11:41:21.000 INFO  runtime.busevents - SensorA state updated to 17
11:41:21.004 INFO  runtime.busevents - SensorB state updated to 20

Upvotes: 1

Views: 482

Answers (1)

happyhairydude
happyhairydude

Reputation: 178

we use a sed script along these lines:

s/.* error .*/^[[31m&^[[0m/
t done
s/.* warning .*/^[[33m&^[[0m/
t done

:done

and invoke it by

sed -f log_color.sed

I guess you could do something similar?

Upvotes: 3

Related Questions