如何使用尾部或更少的颜色来查看彩色日志?

时间:2021-11-26 05:40:27

如何使用尾部或更少的颜色来查看彩色日志?

Reading a Rails log with vim, we can see a colored log. But when we use tail -f or less to watch the log, it isn't colorized anymore. Is there any way to see the colored log with tail or less or whatever?

使用vim读取Rails日志,我们可以看到彩色日志。但是当我们使用tail -f或更少来查看日志时,它不再着色了。有没有办法看到有尾巴或更少的彩色日志或其他什么?

3 个解决方案

#1


19  

pass -R to less for it to let colour escape sequences pass through, i.e.

将-R传递给less以使颜色转义序列通过,即

less -R log/development.log

This should result in them being displayed in colour, assuming you are using the proper terminal type

假设您使用正确的终端类型,这应该导致它们以彩色显示

#2


4  

tail -f log/development.log | ccze -A

You may need to install ccze

您可能需要安装ccze

sudo apt-get install ccze

it works better, not ideal but works

它效果更好,不理想但有效

#3


1  

You can't do that out of the box, since tail and less know nothing about Rails, and logs are saved a simple text files. You could use regular expressions to colorize output but I doubt it's worth the trouble.

你不能开箱即用,因为尾巴和Rails一无所知,日志保存了一个简单的文本文件。您可以使用正则表达式着色输出,但我怀疑这是值得的麻烦。

EDIT: see alfonso's comment for some alternatives.

编辑:请参阅alfonso对某些替代方案的评论。

#1


19  

pass -R to less for it to let colour escape sequences pass through, i.e.

将-R传递给less以使颜色转义序列通过,即

less -R log/development.log

This should result in them being displayed in colour, assuming you are using the proper terminal type

假设您使用正确的终端类型,这应该导致它们以彩色显示

#2


4  

tail -f log/development.log | ccze -A

You may need to install ccze

您可能需要安装ccze

sudo apt-get install ccze

it works better, not ideal but works

它效果更好,不理想但有效

#3


1  

You can't do that out of the box, since tail and less know nothing about Rails, and logs are saved a simple text files. You could use regular expressions to colorize output but I doubt it's worth the trouble.

你不能开箱即用,因为尾巴和Rails一无所知,日志保存了一个简单的文本文件。您可以使用正则表达式着色输出,但我怀疑这是值得的麻烦。

EDIT: see alfonso's comment for some alternatives.

编辑:请参阅alfonso对某些替代方案的评论。