you can redirect your script's STDOUT to an in-memory file in a BEGIN block, then at the END, print the contents of that in-memory variable to a logfile and to the original STDOUT handle
I have tried this approach. It is working in the test environment and has been applied to one of the production scripts that I use quite a bit and from which I regularly get 500 errors. And of course, I keep testing and it isn't giving errors...but I am sure it will before long!
Here is what the top of the script looks like...
#!/usr/bin/perl -T use CGI::Carp qw(fatalsToBrowser); use FindBin qw($RealBin); my $safepath; { use autodie; my $fh_cgiout; my $memory; BEGIN { open $fh_cgiout, '>&', \*STDOUT; close STDOUT; open STDOUT, '>', \$memory; } END { close STDOUT; open my $fh, '>>', 'dupot.log'; print $fh "-----\n"; my $prefix = sprintf "DEBUG %5d %s: ", $$, scalar localtime; print {$fh} ($memory =~ s/^/$prefix/gmr); close $fh; open STDOUT, '>&', $fh_cgiout; print $memory; } } BEGIN { if ($RealBin =~ m!^(/home/xxx/yyy/(test|uk)/www)!) { $safepath = "$1/../lib"; } else { die "Illegal use of software - visit www.way-finder.uk to use +this site"; } } use lib "$safepath";
The braces around the first BEGIN and END block are to limit the scope of use autodie; - is that right and is that 'all' they are doing?
I can see what print {$fh} ($memory =~ s/^/$prefix/gmr); is doing but could not write it from scratch! The braces are needed because the thing that is printed is being calculated on the fly instead of being a constant or intopolated from a variable - is that right?
Thanks for your help thus far...I have a rapidly growing log file capturing all the stuff output to people's browsers. Hopefully somewhere in that lot I will find the clue that unlocks my understanding of the error.
In reply to Re^3: Errors uncaught by CGI::Carp
by Bod
in thread Errors uncaught by CGI::Carp
by Bod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |