Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, This feels more like an apache question than a perl question but have run out of ideas, so I thought I would try.

I have a simple filter script that I would like to use to filter out the apache error logging into my script and then into the cronolog script.

However, I only get the apache 'resuming normal operations' and then nothing ever again. I thought it might be buffering so I tried making STDOUT hot, but no luck.

Here is the code:

#!/usr/bin/perl -T use strict; use warnings; $|++; my $line = shift( @ARGV ); unless( defined( $line ) ){ $line = <STDIN>; } select STDOUT; $|=1; print STDOUT "$line\n" if( defined( $line ) && $line !~ m/favicon/ig ) +; exit(0);
In the http.conf for the error log it used to be "|cronolog ..." and now its "|myscript.pl|cronolog ...". Any suggestions would be greatly appreciated.

Replies are listed 'Best First'.
Re: How do I pipe Apache to my script then to cronolog?
by kwaping (Priest) on Sep 25, 2006 at 21:33 UTC
    It seems to me that your program is doing exactly what you're telling it to. It reads a line of STDIN and prints it to STDOUT, then exits.

    You might want to try something along these lines:
    while (<STDIN>) { print STDOUT "The next line is: $_\n"; }
    A minor note, I think your select and exit are superfluous. For that matter, so is the STDOUT in print STDOUT.

    Also, explore Apache's Conditional Logging capability.

    ---
    It's all fine and dandy until someone has to look at the code.
      Thanks, I figured it was called each time, I didn't know it needed a loop. I looked around apache site and couldn't find examples and docs.

      Yeah, I was getting desperate and put in the select and exit.

      Excellent. I asked my local sysadmin guru and he said you couldn't do that with apache, so I figured I had to go with a filter. I just want to stop logging all those stupid favicon requests (nothing against favicons, but the site is a wiki and the browsers look in several locations, not just toplevel dir).

      Thanks for the info.
Re: How do I pipe Apache to my script then to cronolog?
by shmem (Chancellor) on Sep 25, 2006 at 21:38 UTC
    Without looking up the pipe facility for apache logging - I'd just replace 'cronolog' with 'myscript.pl' in the apache config, and let my script dispatch to cronolog (whatever that is :-) -
    open(STDOUT,"| cronolog") or die "Can't run cronolog: $!\n";

    and make shure a) apache finds the script (i.e. it's in it's $PATH), b) it is executable by the efective UID of apache.

    That way I'd avoid requesting from apache to be able to parse and behave like a shell.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}