[Spread-users] Updated error_log_spread.pl for mod_log_spread
Rob Bloodgood
rob at exitexchange.com
Thu Aug 23 22:36:01 EDT 2007
I found that error_log_spread.pl in the mod_log_spread distribution
(1.0.4), dated 2000, needed a little work.
When I tried it, it turned out my spread-based error_log lacked
newlines. (?)
Since I speak perl, I looked and this was a simple fix, one line.
So while I was at it, I added a small feature: -h will already include
the hostname that sent the message in the log message. I added -a to
include (instead) the _short_ hostname, eg www1 instead of
www1.myfullyqualifieddommainname.com.
This works *great* in production, and I have this apache ErrorLog directive:
ErrorLog "|/usr/local/bin/error_log_spread.pl -a -h -g www_error_log"
This gives me log entries like (sorry if it wraps):
www1 [Thu Aug 23 19:26:45 2007] [error] [client ###.###.###.###] File
does not exist: /var/www/_vti_bin/owssvr.dll
Attached is a diff.
-------------- next part --------------
--- error_log_spread.pl 2000-10-14 21:08:04.000000000 -0700
+++ /usr/local/bin/error_log_spread.pl 2007-08-23 19:27:24.000000000 -0700
@@ -18,16 +18,16 @@
$| = 1;
# Read in options
-getopts('dg:hs:', \%opts);
+getopts('adg:hs:', \%opts);
$debug = $opts{d};
&usage() unless ($group = $opts{g});
$hosttoggle = $opts{h};
-$spreaddaemon = ($opts{s}?$opts{s}:3333);
+$spreaddaemon = ($opts{'s'}?$opts{'s'}:3333);
# Set spread connection params
#$hostname = `hostname`;
-chomp ($hostname = `hostname`) ;
+chomp ($hostname = $opts{a} ? `hostname -s` : `hostname`) ;
$args{'spread_name'} = $spreaddaemon;
$args{'private_name'} = "$$-$hostname";
$args{'priority'} = 0;
@@ -35,18 +35,16 @@
# Connect to daemon
print "Trying to connect to spread...\n" if $debug;
-($mbox, $privategroup) = Spread::connect(
- \%args
- );
+($mbox, $privategroup) = Spread::connect( \%args );
print "$sperrno\n" unless (defined($mbox) && $debug);
#Logging loop
while(<STDIN>){
-chomp;
-print "MESSAGE $_\n";
+ # chomp; # spreadlogd doesn't replace this, so don't throw it away.
+ print "MESSAGE $_";
if(($ret = Spread::multicast($mbox,
RELIABLE_MESS, $group, 0,
- ($hosttoggle?$hostname." ".$_:$_)))>0) {
+ ($hosttoggle ? "$hostname $_" : $_))) > 0) {
print STDERR "Successfully multicasted $ret bytes to [$group]\n" if $debug;
} else {
print STDERR "Failed multicast $_ to $group: $sperrno\n" if $debug;
@@ -54,7 +52,7 @@
}
sub usage(){
- print STDERR "Usage: Logger -g group [-h] [-s daemon] [-d]\n";
+ print STDERR "Usage: Logger -g group [-h] [-a] [-s daemon] [-d]\n";
exit 0;
}
More information about the Spread-users
mailing list