Hi,

I am using apache with mass virtual hosting. I need to keep separate log files for each vhosts into something like thist
/var/log/httpd/$vhost.without.www/$year/$month/$day/access.log


I have found a little perl script that says it does that. Unfortunatelly it does not working, apache error.log saying something like this:
piped log program '/usr/local/sbin/logger' failed unexpectedly


Here is the perl script
###start program ###
#!/usr/bin/perl
#Script to pipe apache log entries to virtually hosted log files
# Assumes httpd.conf has the following:
# LogFormat "%v %h %l %u %t \"%r\" %>s %b" commonvhost
# and that ONLY the following logging line is used in the httpd.conf:
# CustomLog "| /path/to/logger.pl" commonvhost
# DO NOT configure the CustomLog directive in the vhost stubs for vhosts
# or this will not work.
# Script logs commonvhost entries to a logfile with a template of:
# /var/log/httpd/virtual.domain/$year/$month/$day
use strict;
my $logEntry = <>;
# get the vhost from this log entry:
$logEntry=~/(.*?) /;
my $vhost = $1;
my ($year, $month, $day) = (
(localtime)[5]+1900,
sprintf("%02d", (localtime)[4]+1),
sprintf("%02d", (localtime)[3])
);
# Name of access logfiles:
my $accessLogName = "vhosts_log";
my $logDir = "/var/log/httpd";
my $allLogDir = "$logDir/all/$year/$month/$day";
my $vhostLogDir = "$logDir/$vhost/$year/$month/$day";
writeLog($allLogDir, "all");
writeLog($vhostLogDir, "vhost");
# write a log entry to a file
sub writeLog(){
my $logDir = shift @_;
my $type = shift @_;
if( ! -d $logDir ) {
`mkdir -p $logDir`;
}
open(FD, ">>$logDir/$accessLogName");
# if type is vhost, strip off the vhost data:
if($type eq "vhost"){
$logEntry =~s/.*? //;
}
print FD $logEntry;
close FD;
}
###end program ###


Can anyone tell me what have I done wrong ?

Thank you very much!


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]




Reply via email to