This is a discussion on Piping messages in a CustomLog within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi, I've been trying all day to get Apache to pipe log messages to a Perl script. Shouldn't ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I've been trying all day to get Apache to pipe log messages to a Perl script. Shouldn't be too difficult, but it simply isn't working. Here's my configuration entry: CustomLog "|logs/custom_log.pl" combined I've tried this both in VirtualHost directives and outside of them. I've also tried prepending "perl" and an absolute path to the perl executable, and using an absolute path to the script. Using a custom log to a simple log file works fine. And here's the logs/custom_log.pl file: #!usr/bin/perl -w open LOG_OUT, "> logs/custom.log" or die $!; print LOG_OUT "this is a test\n"; while (<STDIN>) { print LOG_OUT $_; } I've also tried using an absolute path to the custom.log file. The script runs fine when I call it from the command line in the Apache root. This is on WinXP, Apache 2.0.44, Perl v5.8.6 (IndigoPerl build). Any help would be appreciated. Walter Gildersleeve Freiburg, Germany |
|
|||
|
NullBock wrote:
> Hi, > > I've been trying all day to get Apache to pipe log messages to a Perl > script. Shouldn't be too difficult, but it simply isn't working. > Here's my configuration entry: > > CustomLog "|logs/custom_log.pl" combined > > I've tried this both in VirtualHost directives and outside of them. > I've also tried prepending "perl" and an absolute path to the perl > executable, and using an absolute path to the script. Using a custom > log to a simple log file works fine. > > And here's the logs/custom_log.pl file: > > #!usr/bin/perl -w > open LOG_OUT, "> logs/custom.log" or die $!; > print LOG_OUT "this is a test\n"; > while (<STDIN>) { > print LOG_OUT $_; > } > > I've also tried using an absolute path to the custom.log file. The > script runs fine when I call it from the command line in the Apache > root. > Maybe you want to reset $| (in your Perl script) to autoflush the output... Xicheng |
|
|||
|
Davide Bianchi wrote:
> On 2006-08-16, NullBock <noted_rogue@easypeas.net> wrote: > > I've been trying all day to get Apache to pipe log messages to a Perl > > > And here's the logs/custom_log.pl file: > > > > #!usr/bin/perl -w > > What's this? A relative path or what? Shouldn't be #!/usr/bin/perl ? > > > This is on WinXP, > > And on WinXP there is /usr/bin ? > > Davide Good eye, Davide. Didn't help, though. Win32 doesn't use the shebang line, so it could be anything. I even tried giving an absolute path to the Perl executable, no dice. I do suspect it's a Windows problem, I hope a solveable one. I was hoping someone had some experience with it... Walter |
|
|||
|
Xicheng Jia wrote: > > Maybe you want to reset $| (in your Perl script) to autoflush the > output... > > Xicheng Hi Xicheng, Tried it without luck. The custom.log file isn't even being created! So here's the reworked Perl script, with your and Davide's suggestions (plus a bit better error handling): #!/usr/bin/perl -w open LOG_OUT, "> logs/custom.log" or *LOG_OUT = *STDOUT; select *LOG_OUT; $| = 1; print "this is a test\n"; while (<STDIN>) { print $_; } Walter P.S. What I forgot to mention in my first post: nothing shows up in the error log about this, even if I set the log level to debug. |
|
|||
|
"NullBock" <noted_rogue@easypeas.net> schreef in bericht
news:1155851777.123801.321620@p79g2000cwp.googlegr oups.com... > Davide Bianchi wrote: > > On 2006-08-16, NullBock <noted_rogue@easypeas.net> wrote: > > > #!usr/bin/perl -w > Good eye, Davide. Didn't help, though. Win32 doesn't use the shebang > line, so it could be anything. I even tried giving an absolute path to > the Perl executable, no dice. > > I do suspect it's a Windows problem, I hope a solveable one. Assuming perl.exe is available via path _before_ logon, try CustomLog "| perl logs/custom_log.pl" combined otherwise add the local full path -and perhaps even the extention- Note: open LOG_OUT, "> logs/custom.log" or die $!; will overwrite the log at every restart of the service. HansH |
|
|||
|
HansH wrote: > Assuming perl.exe is available via path _before_ logon, try > CustomLog "| perl logs/custom_log.pl" combined > > otherwise add the local full path -and perhaps even the extention- It worked! Thought I'd already tried it, but there you go. Ended up having to add the absolute path with extension, even though the perl executable was on the PATH. Now I've got a problem printing the actual events (ie, the while loop doesn't execute)--I'm going to go to sleep, and deal with it tomorrow. > Note: open LOG_OUT, "> logs/custom.log" or die $!; > will overwrite the log at every restart of the service. > > HansH I know. This is just a quick hack to see if I can get it to work. Thanks, Walter |
|
|||
|
"NullBock" <noted_rogue@easypeas.net> schreef in bericht
news:1155854870.653610.154540@i42g2000cwa.googlegr oups.com... > > Assuming perl.exe is available via path _before_ logon, try > > CustomLog "| perl logs/custom_log.pl" combined > > > > otherwise add the local full path -and perhaps even the extention- > > It worked! Thought I'd already tried it, but there you go. Ended up > having to add the absolute path with extension, even though the perl > executable was on the PATH. Now I've got a problem printing the actual > events (ie, the while loop doesn't execute)--I'm going to go to sleep, > and deal with it tomorrow. > Apache might be writing single character line ends where perl _on_windows_ is expecting two characters. Try changing the input seperator by adding on top of your script $/ = "\012"; # LineFeed without preceding CarriageReturn Donīt forget to flush the output by $| = 1; What _is_ written to the file anyway? HansH |
|
|||
|
HansH wrote:
> Apache might be writing single character line ends where perl _on_windows_ > is expecting two characters. Try changing the input seperator by adding on > top of your script > $/ = "\012"; # LineFeed without preceding CarriageReturn > > Donīt forget to flush the output by $| = 1; > > What _is_ written to the file anyway? > > HansH Hi HansH, I tried it, but it didn't seem to do anything. Here's the Perl script now: #!/usr/bin/perl -w open LOG_OUT, "> logs/custom.log" or *LOG_OUT = *STDOUT; select *LOG_OUT; $| = 1; $/ = "\012"; print "this is a test\n"; while (<STDIN>) { print "gonna print STDIN text\n"; print $_; } When I run it from the command line and type "another," this is the output: this is a test gonna print STDIN text another But from Apache, only this is a test is printed, nothing more. Here's the complete VirtualHost config entry: <VirtualHost *:80> ServerName 127.0.0.1 CustomLog "| C:/indigoperl/perl/bin/perl.exe logs/custom_log.pl" combined # CustomLog logs/custom.log combined DocumentRoot "J:/apache/htdocs" </VirtualHost> If I use the static CustomLog entry instead of the Perl one, it does what you'd expect, ie: 127.0.0.1 - - [18/Aug/2006:11:04:48 +0200] "GET /index.htm HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" after going to localhost/index.htm This might be moving into a Perl question--maybe I should ask in the Perl group. I'll also trying running it with a different script language, and see what that does. Walter |