httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jez Hancock <jez.hanc...@munk.nu>
Subject Re: [users@httpd] Windows Apache logrotate
Date Thu, 04 Dec 2003 20:19:35 GMT
On Thu, Dec 04, 2003 at 11:07:05AM -0800, Ian Huynh wrote:
> logrotate vs cronolog? 
> 
> http://www.cronolog.org/
> 
> I am curious as to which is the preferred method?
cronolog is ok, but it does eat up a lot of file descriptors - 2(?) per
logging pipe.  I've never used logrotate - for my main request logging I
use this:

CustomLog "| /usr/local/sbin/logger.pl" commonvhost

where logger.pl looks like this:

-snip-
#!/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.

# File logs commonvhost entries to a logfile with a template of:
# /var/log/httpd/virtual.domain/$year/$month/$day

use strict;

=comment
my $sample = 'www.savelua.com 68.35.248.247 - - [13/Jul/2003:00:01:28 -0500] "GET
/images/link_images/br_to_uk.png HTTP/1.1" 200 10202
"http://forums.devshed.com/t66206/sfd0f2685db185532b3c8e1ae5b7bebfe.html"
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"
';
$_=$sample;
=cut

my $logEntry = <>;

# get the vhost from this log entry:
$logEntry=~/(.*?) /;
my $vhost = $1;

# strip leading www.:
$vhost=~s/^www\.//;

my ($year, $month, $day) = (
	(localtime)[5]+1900,
	sprintf("%02d", (localtime)[4]+1),
	sprintf("%02d", (localtime)[3])
);

# Name of access logfiles:
my $accessLogName = "httpd-access.log";


=comment
$logdir:
Location to put all logfiles

This will log everything into:
$logdir/all/$year/$month/$day/httpd-access.log

and put individual vhost logfiles into:
$logdir/$vhost/$year/$month/$day/httpd-access.log
=cut

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;
}
-snip-

This script does me for now (around 50 vhosts), although I'm considering
changing the script above so it uses a fifo(?) to handle higher volume
hitrates better.  If anyone has any suggestions please let me know - I'm
not too sure how to do it.  I did find a decent perl script somewhere
someone had come up with that did an almost identical task to the above
but using a more reliable method - can't for the life of me find the
script now :(

-- 
Jez Hancock
 - System Administrator / PHP Developer

http://munk.nu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message