Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Redirect Apache Logs to both STDOUT and Apache Log File

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!

like image 774
Ritesh Avatar asked Feb 27 '17 10:02

Ritesh


People also ask

How do I send Apache logs to syslog?

Apache doesn't only support logging to files. For example, you can also send logs directly to a syslog service using a custom logging pipeline. The most common method is to use the /usr/bin/logger command, which forwards logs over a syslog socket to the syslog service.

How do I change the Apache access log format?

The LogFormat directive controls the layout and formatting of log events. Apache uses the Common Log Format (CLF) by default, but you can specify your own format string to change the fields included in each log. You can also use the CustomLog directive to change the location of the log file.


1 Answers

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".)

like image 59
Maoz Zadok Avatar answered Nov 15 '22 05:11

Maoz Zadok