
We're occasionally asked if customers can view the output of the Apache Web server error log to debug Perl scripts. Unfortunately, we don't currently provide direct access to the error log for security reasons (all sorts of information from different customers is mixed together in a way that's hard to separate reliably).
There are other options for Perl that work well, though (in fact, they actually work more reliably). We've included a few of those below.
If your script just dies and you want to see the error, you can add the following extra text as the second line of your Perl script, right below the "#!/usr/bin/perl" line:
use CGI::Carp qw(fatalsToBrowser);
This will display the Perl errors in your Web browser when you run the script. (You should remove this line once you've solved the problem, as it can potentially reveal parts of your script's source code to your visitors.)
If you want to do a similar thing with Perl warnings as well, use this instead:
use CGI::Carp qw(fatalsToBrowser warningsToBrowser); # ... some code that prints the HTTP header ... warningsToBrowser(1);
That will include any Perl warnings in the Web page as embedded HTML comments. Just be careful that you don't call warningsToBrowser(1); until after you print the HTTP header (see the CGI::Carp documentation for details about this).
If you don't want errors or warnings to appear in the script's Web browser output, you can create a separate, private error log instead. This code will do that:
BEGIN {
use CGI::Carp qw(carpout);
open(LOG, ">>/home/ex/example.com/cgi.log") or
die("Unable to open log: $!\n");
carpout(LOG);
}
The log file will contain the contents of any Perl warnings or errors — it acts like the Apache error log, but it's more reliable.
Again, for more details about this kind of thing, we strongly recommend the CGI::Carp documentation.
We know that sometimes it would just be easier to see a reliable, secure copy of the Apache error log messages for your site. We're working on that feature, and hope to have it available as a future improvement to our service.