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

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?

链接地址: http://www.djcxy.com/p/47104.html

上一篇: 利用emacs'或vim的语法高亮器来执行命令

下一篇: 通过unix管道过滤器输出多彩的控制台