httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jez Hancock <>
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? 
> 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/" commonvhost

where looks like this:

# 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/" 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;

my $sample = ' - - [13/Jul/2003:00:01:28 -0500] "GET
/images/link_images/br_to_uk.png HTTP/1.1" 200 10202
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"

my $logEntry = <>;

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

# strip leading www.:

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

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

Location to put all logfiles

This will log everything into:

and put individual vhost logfiles into:

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;

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

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message