我如何为日志着色/格式化并在不妨碍彼此的情况下进行旋转?

问题描述

将此发布到 Stackoverflow 上,因为 Serverfault 上没有人回答它。

我有以下几点:

通过 screen 执行的 shell 脚本和使用标志 -L 生成的屏幕日志。这个 shell 脚本只是 ncat(netcat 的更好版本)监听内部 IP 上的特定端口。

所以我想完成以下工作:

使用 grc 为传入的日志着色,然后每天对它们进行日志轮换。我已经有了一个配置,我只是不知道如何让这两个工作不会互相妨碍。

总结:

为了给原木着色,我安装了 grc,为了原木轮换,我安装了经典的 logrotate。我显然也安装并配置了 cron 和 crontab。

也许我可以将 grc 管道作为 postrotate 脚本嵌入到配置中?如何与日志旋转一起完成这种着色?

附言日志已经有颜色信息和级别,使用 log4js。

更新

我在我的 cron.daily 中添加了以下内容,但由于某种原因它似乎不起作用,logrotate -d 说不需要轮换日志,因为它已经轮换了,即使事实并非如此 AFAIK:>

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.d/projectnamehere
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0


我的 /etc/logrotate.d/projectnamehere 看起来像这样:

/home/Admin/logging/screenlog* {

# see "man logrotate" for details
# rotate log files daily
daily

# keep 7 days worth of backlogs
rotate 7

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# prevent the rotation from happening if the log is empty
notifempty

# colour the log after rotating
postrotate
               grc /home/Admin/logging/screenlog* > /home/Admin/logging/screenlog.colorized
endscript

}
# system-specific logs may be also be configured here.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...