Apache httpd: Send error logs to syslog and local disk? Without touching /etc/syslog.conf?

13,055

Solution 1

Try sending all of ErrorLog to a pipe, for example a perl script. This perl script could direct to syslog and the local disk.

Solution 2

You can use:

ErrorLog "| tee -a /var/log/httpd/error_log | /usr/bin/logger -t httpd -i -p local4.error"

to do what you are after.

Share:
13,055

Related videos on Youtube

Stefan Lasiewski
Author by

Stefan Lasiewski

Stefan Lasiewski Daddy, Linux Guy, Bicyclist, Tinkerer, Fixer & Breaker of things. I work as a Senior SYstem Engineer at the National Energy Research Scientific Computing Center (NERSC) Division at Lawrence Berkeley National Laboratory (LBNL) in Berkeley, CA. Father of 3 cute children. Yes I'm a sysadmin and a parent. Heavy user of CentOS, RHEL & FreeBSD for production services at work. I also run Ubuntu at home, for the simplicity. I'm a fan of Apache HTTP Server, Nagios & Cacti. Original proposer of unix.stackexchange.com (Yes, this proposal predated askubuntu.com, and I wish they would have merged with the Unix proposal.).

Updated on September 18, 2022

Comments

  • Stefan Lasiewski
    Stefan Lasiewski over 1 year

    I have an Apache httpd 2.2 server. I want to log all messages using syslog, so that the requests are sent to our central syslog server. I also want to ensure that all log messages are sent to local disk, so that a sysadmin can have easy access to the log files on the local system.

    It is easy to send HTTP access logs to both the local disk and to syslog. One common method is:

    LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    CustomLog logs/access_log combined
    CustomLog "|/usr/bin/logger -t httpd -i -p local4.info" combined
    

    But it is not easy to do this for error logs. The following configuration doesn't work, because the error logs only use the last ErrorLog stanza. The first ErrorLog stanza is ignored.

    ErrorLog logs/error_log
    ErrorLog syslog:local4.error
    

    How can I ensure that Apache errors logs are written to the local disk and are sent to syslog?

    Is it possible to do this without touching /etc/syslog.conf ? I am fine if my users want to manage their own Apache configuration files, but I do not want them touching system files such as /etc/syslog.conf

  • Stefan Lasiewski
    Stefan Lasiewski about 12 years
    Something like this well-known Perl script, for example: oreillynet.com/pub/a/sysadmin/2006/10/12/httpd-syslog.html
  • Sirch
    Sirch about 12 years
    Send it to whatever priority is already configured in your syslog.conf, and also open your log file and write $log there too.