我如何开发一个进程让 Apache 将错误日志发送到 Web API?

How can I develop a process to have Apache send error logs to a web API?

如问题所述:如何开发一个进程让 Apache 将错误日志发送到 Web API?

我目前的想法是编写一个脚本来清空错误日志并将其发送到网络 API 并将其作为 cron 作业 运行。但我想知道是否还有其他方法存在?肯定有人比我先有了这个想法:)

您可以将日志通过管道传输到 curl 等外部进程。 Curl 可以将它们传送到网络 API。在您的 Apache 配置文件中添加如下内容:

ErrorLog  "|/usr/bin/tee -a /var/log/apache2/error.log  | /usr/bin/curl URL"
CustomLog "|/usr/bin/tee -a /var/log/apache2/access.log | /usr/bin/curl URL" extended_ncsa