Apache httpd:将错误日志发送到 syslog 和本地磁盘?无需修改 /etc/syslog.conf?

Apache httpd:将错误日志发送到 syslog 和本地磁盘?无需修改 /etc/syslog.conf?

我有一台 Apache httpd 2.2 服务器。我想使用 syslog 记录所有消息,以便将请求发送到我们的中央 syslog 服务器。我还想确保所有日志消息都发送到本地磁盘,以便系统管理员可以轻松访问本地系统上的日志文件。

将 HTTP 访问日志发送到本地磁盘和 syslog 都很容易。一种常见的方法是:

LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog logs/access_log combined
CustomLog "|/usr/bin/logger -t httpd -i -p local4.info" combined

但对于错误日志来说,做到这一点并不容易。以下配置不起作用,因为错误日志仅使用最后一个 ErrorLog 节。第一个 ErrorLog 节被忽略。

ErrorLog logs/error_log
ErrorLog syslog:local4.error

如何确保 Apache 错误日志写入本地磁盘并发送到 syslog?

是否可以在不接触的情况下做到这一点/etc/syslog.conf?如果我的用户想要管理自己的 Apache 配置文件,我没问题,但我不希望他们接触系统文件,例如/etc/syslog.conf

答案1

尝试将所有 ErrorLog 发送到管道,例如 perl 脚本。此 perl 脚本可以指向 syslog 和本地磁盘。

答案2

您可以使用:

ErrorLog "| tee -a /var/log/httpd/error_log | /usr/bin/logger -t httpd -i -p local4.error"

去做你想做的事。

相关内容