I'm setting up a virtual hosting environment with mod_vhost_alias, so I've got to manually split up log files for each client. I figured that would be really simple, and discovered that it was. All I had to do was write a script that takes input on STDIN and have it do what I need to.
The Apache group has
split-logfiles which theoretically does this. But I'm running into a peculiar problem.
When I put it into my Apache log files with:
CustomLog "|/opt/apache/logs/split-logfiles" combined
It opens each file that it is supposed to, but then none of the log entries get written.
I decided to do some testing of my own and wrote this:
#!/usr/bin/perl
$isopen = 0;
while ($log_line = <STDIN>) {
$myfile = "/var/tmp/test.log";
unless($isopen and -f $myfile) {
open MYHAPPYFILE, ">$myfile" or die "Error opening $myfile";
$isopen = 1;
}
printf MYHAPPYFILE "%s", $log_line;
}
exit 0;
And when I put that into apache instead of split-logfiles, it does the same thing:
/var/tmp/test.log gets created but none of the log entries get put into it.
When I tried printing to
STDERR instead of
MYHAPPYFILE, it showed up fine in the error log.
Any ideas?