我有一个运行Apache的docker容器。我希望Apache将日志保存到文件系统(分别访问和错误日志以及滚动)。另外,我希望看到带有docker logs
命令的实时日志。
如何配置在docker容器中运行的Apache同时记录文件和控制台?
答案 0 :(得分:1)
您需要使用tee
命令管道到Apache进程的标准输出流(/proc/1/fd/1
)和rotatelogs
,如下所示:
CustomLog "|$/usr/bin/tee -a /proc/1/fd/1 | bin/rotatelogs -l -n 30 logs/access.log 10M" common
# Apache captures stderr itself and pipes it to itself. As this would make an infinite loop, we use stdout here for Docker (/prod/1/df/1)
ErrorLog "|$/usr/bin/tee -a /proc/1/fd/1 | bin/rotatelogs -l -n 10 logs/error.log 2M"