- Put the following script in /usr/local/bin/apache_syslog.
#!/usr/bin/perl
# $Id$
#
# A wrapper script that logs apache access via syslog. Copied from an example
# at http://oreilly.com/pub/a/sysadmin/2006/10/12/httpd-syslog.html
# Script requires sysutils/p5-Sys-Syslog from FreeBSD ports.
#
use Sys::Syslog qw( :DEFAULT setlogsock );
# Excluded, per the rules of Sys:Syslog
# http://search.cpan.org/~saper/Sys-Syslog-0.29/Syslog.pm#THE_RULES_OF_SYS::SYSLOG
#setlogsock('unix');
openlog('httpd', "cons, pid", 'local2');
while ($log =) {
syslog('notice', $log);
}
closelog; - Install sysutils/p5-Sys-Syslog from ports (FreeBSD).
- In your Apache config replace your ErrorLog directive with "ErrorLog syslog:local1".
- Replace your CustomLog directive (for access logs) with "CustomLog |/usr/local/bin/apache_syslog combined".
- Edit /etc/syslog.conf, adding the following lines
!httpd
local1.* /var/log/httpd-error.log
local2.* /var/log/httpd-access.log
!* - Create the log files with "touch /var/log/httpd-error.log /var/log/httpd-access.log".
- Edit /etc/newsyslog.conf, adding the following lines
/var/log/httpd-error.log 640 14 * @T00 J
/var/log/httpd-access.log 640 14 * @T00 J - (Re)start syslogd and apache.
- Profit.
Friday, September 2, 2011
Apache syslogging on FreeBSD
If you need to use Syslog to send Apache log output there are plenty of examples already on the Internet. The first hit on google was the O'Reilly Sysadmin blog, which is very useful. However, the page is a bit old and the perl script they provide for Syslogging access logs is in need of updating. My modified version is below. To summarize the process..
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment