- 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.
Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts
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..
Tuesday, August 9, 2011
Clearing my mental hang-ups about Perl
The script below does some simple things to demonstrate to myself how a number of things work in Perl. Simple things, but ones that I sometimes have to stop and think twice about.
use Config::Auto;
# Test Config::Auto output, which should be a reference
my $ca = Config::Auto->new(
source => "test.conf",
format => "equal"
);
my $config = $ca->parse;
print "\$config is a " . ref($config) . " reference\n" if (ref $config);
print "c_one undefined\n" unless (defined $config->{'c_one'});
print "c_two undefined\n" unless (defined $config->{'c_two'});
print "c_three undefined\n" unless (defined $config->{'c_three'});
print "c_one non-existent\n" unless (exists $config->{'c_one'});
print "c_two non-existent\n" unless (exists $config->{'c_two'});
print "c_three non-existent\n" unless (exists $config->{'c_three'});
# Test a non-referenced hash
my %harsh=(
'one' => 1,
'two',
);
print "\$harsh is a " . ref($harsh) . " reference\n" if (ref $harsh);
print "one undefined\n" unless (defined $harsh{'one'});
print "two undefined\n" unless (defined $harsh{'two'});
print "three undefined\n" unless (defined $harsh{'three'});
print "one non-existent\n" unless (exists $harsh{'one'});
print "two non-existent\n" unless (exists $harsh{'two'});
print "three non-existent\n" unless (exists $harsh{'three'});
# Test array interpolation
my @array = ("one", "two");
print "\@array interpolated is: @array\n\@array not interpolated is " . @array . "\n\$\#array is $#array\n";
The test.conf file referred to above contains the following:
c_one = 1
c_two =
The following output is generated by the script:
$config is a HASH reference
c_three undefined
c_three non-existent
two undefined
three undefined
three non-existent
@array interpolated is: one two
@array not interpolated is 2
$#array is 1
use Config::Auto;
# Test Config::Auto output, which should be a reference
my $ca = Config::Auto->new(
source => "test.conf",
format => "equal"
);
my $config = $ca->parse;
print "\$config is a " . ref($config) . " reference\n" if (ref $config);
print "c_one undefined\n" unless (defined $config->{'c_one'});
print "c_two undefined\n" unless (defined $config->{'c_two'});
print "c_three undefined\n" unless (defined $config->{'c_three'});
print "c_one non-existent\n" unless (exists $config->{'c_one'});
print "c_two non-existent\n" unless (exists $config->{'c_two'});
print "c_three non-existent\n" unless (exists $config->{'c_three'});
# Test a non-referenced hash
my %harsh=(
'one' => 1,
'two',
);
print "\$harsh is a " . ref($harsh) . " reference\n" if (ref $harsh);
print "one undefined\n" unless (defined $harsh{'one'});
print "two undefined\n" unless (defined $harsh{'two'});
print "three undefined\n" unless (defined $harsh{'three'});
print "one non-existent\n" unless (exists $harsh{'one'});
print "two non-existent\n" unless (exists $harsh{'two'});
print "three non-existent\n" unless (exists $harsh{'three'});
# Test array interpolation
my @array = ("one", "two");
print "\@array interpolated is: @array\n\@array not interpolated is " . @array . "\n\$\#array is $#array\n";
The test.conf file referred to above contains the following:
c_one = 1
c_two =
The following output is generated by the script:
$config is a HASH reference
c_three undefined
c_three non-existent
two undefined
three undefined
three non-existent
@array interpolated is: one two
@array not interpolated is 2
$#array is 1
Subscribe to:
Posts (Atom)
