in reply to Re: Re: CGI file writing
in thread CGI file writing

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.

Replies are listed 'Best First'.
Re: Re: Re: Re: CGI file writing
by mcogan1966 (Monk) on Oct 29, 2003 at 14:47 UTC
    That's not what I'm doing here.
    This is a custom search engine, and I'm saving some of the search paramaters each time a search is done. This data is to be stored in a specific location. Problem was, I couldn't figure out where to get it to start without having to hard-code the directory structure in. STDERR isn't the solution I'm looking for.