|
Hi, I’m creating a perl script that takes incoming http/s requests, logs the standard input, output and error, before returning the output to the client. The input, output and error log is appended after each HTTP request.
The problem I’m having is that I’m trying to add a header line to the log files each time they are appended. For example if a new http request is made, a header will be added to each of the logs before the new standard data is added. This will most likely contain the “$date†and “$time†to enable the user to locate their most recent http request in the logs.
I am unsure how to add this header before the STDERR, STDIN and STDOUT are sent to their corresponding logs. Can anyone point me in the right direction? Any help would be much appreciated. Thanks.
****************************************************************
#!/usr/local/bin/perl -w
use CGI qw(:standard);
use Cwd;
#Get the current date & time
($Second, $Minute, $Hour, $Day, $Month, $Year) = localtime(time);
$Year += 1900;
$Month++;
$date = "$Day.$Month.$Year";
$time = "$Hour:$Minute:$Second";
#Send the standard Error, Input and teed output to a log file
open (STDERR, ">> /tmp/$date-error.log") or die "can't connect to error.log: $!";
open (STDIN, ">> /tmp/$date-input.log") or die "can't connect to input.log: $!";
open (STDOUT, "| tee -a /tmp/$date-output3.log") or die "Can't connect to output.log: $!";
#Get the current working directory
$cgi_dir = getcwd();
# Serve the user
$result = system($cgi_dir . "/test-cgi");
exit $result;
#Close the standard output, input and error
close(STDERR) or die "Can't close error: $!\n";
close(STDIN) or die "Can't close input: $!\n";
close(STDOUT) or die "Can't close output: $!\n";
****************************************************************
|
|
|
|
|
|
|
// |