使用 anonip.py 将 Apache 日志中的 IP 匿名化与使用 Cronolog 的日志轮换相结合

Combine anonymization of IPs in Apache logs using anonip.py with log rotation using Cronolog

真希望我来对地方了。

我想匿名化日志文件中的 IP 地址(参见 here),同时在 Ubuntu 16.04.

上使用 Cronolog 轮换日志文件

这是对我当前的 CustomLog 条目的轻微推导:

CustomLog "|/usr/bin/python2.7 /var/www/anonip.py --output |/usr/bin/cronolog /var/www/test.mydomain/log/%Y-%m/access_%d.log" combined

如果我省略 cronolog,它确实有效,但没有。有谁知道如何使这项工作?替代品也很受欢迎。谢谢!

构建一个由多个命令组成的日志记录管道:

CustomLog "|$ /usr/bin/python2.7 /var/www/anonip.py | /usr/bin/cronolog /var/www/test.mydomain/log/%Y-%m/access_%d.log" combined

(省略了选项 --output,它将匿名日志写入文件而不是 stdout

使用 |$ ... 而不是 | ... Apache2 的 CustomLog 启动 shell 可以在管道中启动多个命令而不是单个命令,如 [=14 中所述=].