Apache日志的颜色尾巴

tail –f监视apache日志往往让人非常沮丧。 是否有任何工具/选项着色日志输出? 也许用红色等信号致命

我正在使用multitail监视日志,它包括着色以及多个日志文件监视或者合并或者在窗口中。 试一试。

任何你不能使用这样的东西的原因:

 tail -f FILE | grep --color=always KEYWORD 

来源: commandlinefu.com

发现这个: http : //fixunix.com/unix/83044-tail-color.html

 tail -f file | perl -pe 's/keyword/\e[1;31;43m$&\e[0m/g' 

这只适用于ANSIterminal,但其他所有的terminal已经实际上已经绝迹。 \ e […是ANSI转义序列SGR“select graphic rendition”。 “…”可以用一些分号分隔的整数replace,其含义是:

0:closures所有属性1:粗体31:前景红色43:背景黄色

“关键字”当然可以是任何perl正则expression式:

(foo | bar)突出显示stringfoo和bar \ b((foo | bar)\ b突出显示单词foo和bar。 \ b((foo | bar)\ b。突出显示包含单词foo或bar

或者,简单的方法,只要安装colortail它可能在你最喜欢的回购(对于CentOS的colortail

http://developwithstyle.com/articles/2010/04/20/tail-your-logs-with-a-touch-of-color.html

http://joakimandersson.se/projects/colortail/

我用 grep组合的小脚本来获得一些颜色:

 #!/bin/bash shopt -s expand_aliases alias grey-grep="GREP_COLOR='1;30' grep -E --color=always --line-buffered" alias red-grep="GREP_COLOR='1;31' grep -E --color=always --line-buffered" alias green-grep="GREP_COLOR='1;32' grep -E --color=always --line-buffered" alias yellow-grep="GREP_COLOR='1;33' grep -E --color=always --line-buffered" alias cyan-grep="GREP_COLOR='1;36' grep -E --color=always --line-buffered" tail -1000f /var/log/apache2/error.log | grey-grep ".*PerformanceLogger.*|$" | cyan-grep "INFO|$" | yellow-grep "WARN|$" | red-grep "[ERROR].*|[FATAL].*|$" | green-grep "***|$" 

重点是每个链接的grep添加不同的颜色。 所以结果是这样的: Apache日志有一些颜色

无耻的插件:我写了一个名为TxtStyle的工具,它和前面提到的选项类似。 你可以运行它如下:

 tail -f /var/log/syslog | txts --regex '\d+' 

您还可以在configuration文件( ~/.txts.conf )中定义命名的样式并像这样使用它:

 ifconfig | txts --name ifconfig 

ifconfig样式是定义在框外)

有一个function,我没有看到这些颜色 – 突出反应时间(更高的时间 – >更惊人的颜色)。 现代terminal仿真器中的256色支持在这里很有用。

另一个有用的grep技巧来显示所有的输出,但是所选的KEYWORD的颜色是:tail -f FILE | grep –color = always -E“$ | REGEXP”