I am running a docker container and want to write logs of my apache server to both STDOUT and file.
Any idea as to what kind of configuration is needed in my Apache httpd.conf file?
Any help would be highly appreciated!
I am running a docker container and want to write logs of my apache server to both STDOUT and file.
Any idea as to what kind of configuration is needed in my Apache httpd.conf file?
Any help would be highly appreciated!
you can try this:
CustomLog "| /usr/bin/tee /var/log/access_log" common
from apache.org docs: Apache httpd is capable of writing error and access log files through a pipe to another process, rather than directly to a file. This capability dramatically increases the flexibility of logging, without adding code to the main server. In order to write logs to a pipe, simply replace the filename with the pipe character "|", followed by the name of the executable which should accept log entries on its standard input. Apache will start the piped-log process when the server starts, and will restart it if it crashes while the server is running. (This last feature is why we can refer to this technique as "reliable piped logging".)
2.4.43-alpine
, and I wanted to write the logs out both to stdout and to a file on a volume. I could write them to stdout with CustomLog /proc/self/fd/1 common
, and to a file with CustomLog /usr/local/apache2/logs/access.log common
, but CustomLog "|/proc/self/fd/1 /usr/local/apache2/logs/access.log" common
caused the error Permission denied: AH00104: unable to start piped log program
. Substituting /usr/bin/tee
for /proc/self/df/1
made it work. π β
Northing Slight tweak to @maoz-zadok's answer, which did the trick for me after battling with this problem for an hour or two. Thanks Maoz! π
I'm running a container with 2.4.43-alpine, and I wanted to write the logs out both to stdout and to a file on a volume. I could write them to stdout with
CustomLog /proc/self/fd/1 common
and to a file with
CustomLog /usr/local/apache2/logs/access.log common
but
CustomLog "|/proc/self/fd/1 /usr/local/apache2/logs/access.log" common
caused the error Permission denied: AH00104: unable to start piped log program
.
Substituting /usr/bin/tee
for /proc/self/df/1
made it work, so for me the solution was
CustomLog "|/usr/bin/tee /usr/local/apache2/logs/access.log" common
In case you're building a Docker image, put this in your Dockerfile after the apache package is installed
#This command is used to replace the default values for ErrorLog and CustomLog in the httpd.conf file with a pipe command to redirect logs to both file and console
RUN sed -ri \
-e 's!^(\s*CustomLog)\s+\S+!\1 "| /usr/bin/tee /var/log/access_log"!g' \
-e 's!^(\s*ErrorLog)\s+\S+!\1 "| /usr/bin/tee /var/log/error_log"!g' \
"/etc/httpd/conf/httpd.conf"
Reference : https://github.com/docker-library/httpd/blob/master/2.4/Dockerfile
© 2022 - 2024 β McMap. All rights reserved.