着色尾部输出 [英] Colorize tail output
问题描述
我一直在尝试使尾部对服务器启动更具可读性.我当前的命令从启动中过滤掉了大多数INFO和DEBUG消息:
I've been trying to make tail a little more readable for server startups. My current command filters out most of the INFO and DEBUG messages from the startup:
tail -F ../server/durango/log/server.log | grep -e "ERROR" -e "WARN" -e "Shutdown" -e "MicroKernel" | grep --color=auto -E 'MicroKernel|$'
我想做的是制作一些将黄色突出显示 WARN (警告),将红色突出显示 ERROR ,将绿色突出显示 MicroKernel .我尝试多次管道输送 grep --color = auto ,但是唯一幸存的颜色是管道中的最后一条命令.
What I would like to do is craft something that would highlight WARN in yellow and ERROR in red, and MicroKernel in green. I tried just piping grep --color=auto multiple times, but the only color that survives is the last command in the pipe.
是否有一个班轮来做到这一点?甚至是多班轮?
Is there a one liner to do this? Or even a many-liner?
推荐答案
是的,有办法做到这一点.也就是说,只要您的终端支持 ANSI转义序列 .这是存在的大多数终端.
yes, there is way to do this. That is, as long as your terminal supports ANSI escape sequences. This is most terminals that exist.
我认为我不需要解释如何grep,sed等.指向颜色正确吗?
I think I don't need explain how to grep, sed etc. point is the color right?
请参见下文,这将使
WARN yellow
ERROR red
foo green
这是示例:
kent$ echo "WARN
ERROR
foo"|sed 's#WARN#\x1b[33m&#; s#ERROR#\x1b[31m&#; s#foo#\x1b[32m&#'
注意:\x1b
是 ESC 字符( ^ V Esc )的十六进制.
Note: \x1b
is hexadecimal for the ESC character (^VEsc).
查看结果:
这篇关于着色尾部输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!