in reply to STDERR and CGI::CARP
The open, append, close logic is compatible with log rotation. Anything capture on STDERR when executing the real CGI script wil be written there. The CGI script can also use the same function to write to the log file. To use the buffering idea you have to capture the output of any methods you use in CGI that want to print to STDOUT. For years, the only methods I used in the CGI module was the ones to retrieve the form values. It is possible that CGI has its own buffer with flush. I'll do something like thislog { my @args = @_; my $fmt = shift @args; open my $fh, ">>", "/var/log/error.log" or return; printf {$fh} $fmt, @args; close $fh; return; }
{ my $buffer = ""; sub _print { my @args = @_; $buffer .= sprintf shift @args, @args; return; } sub _flush { my $content = $buffer; $buffer = ""; local $| = 1; print $content; } } _print($cgi->header( -type => .... )); ...... _flus();
|
|---|