I don't quite understand - you are writing the output of a cgi script to a log file. Do you understand that the webserver usually already has a STDERR log file - the Apache webserver has a log file at /var/log/httpd/error_log and when your perl cgi script writes to STDERR, those log messages appear in that error_log file.
Assuming you already understand that, and you still want to write to a separate log file from your cgi script, then you either have to hardcode the absolute log filename (including the path), or you could use the DOCUMENT_ROOT environment variable to base the log file location on. For example:
my $logfile = qq!$ENV{"DOCUMENT_ROOT"}/my_logfile!;
open(LOG, ">>$logfile") || die "Can't open $logfile: $!";
print LOG "Some message from my CGI script!\n";
But the danger there is that your log file will be accessible under the document root - so if your webserver gets compromised, your log file could be read by the attacker.
I would recommend either having your cgi script write to STDERR so that the message will appear in the standard webserver error log (outside the document root), or hardcode the location of the log file in your script, or put the location of the logfile in a site module that gets "use"d by your cgi script on both your dev server and your prod server.
One other option if you want to keep your log file separate from the standard webserver error log, is to use the environment variable HTTP_HOST or SERVER_NAME to construct an if test around which log file name(and path) to use.
HTH. |