tultalk has asked for the wisdom of the Perl Monks concerning the following question:

Hi:

Two issues. First this code works fine in my first accessed CGI script. I have it in other scripts which I am trying to debug and they return nothing so I assume they are failing compile. If this executes before compile, should it not report the compile errors?

Second question: I want a blank line between each reporting line: This print LOG $blank . "\n"; does not work??

Thanks

#Error Handling BEGIN { my $blank = " "; require 5.004; use CGI::Carp qw(fatalsToBrowser carpout); my $logfile = '/home/jalamior/public_html/httpsdocs/cgi-bin/logs/error +Log/errorFile.log'; open LOG, ">>$logfile" or die "Couldn't append to $logfile: $!\n"; carpout(\*LOG); print LOG $blank . "\n"; };

Replies are listed 'Best First'.
Re: Error Log Files
by choroba (Cardinal) on Mar 07, 2017 at 14:35 UTC
    Have you checked your server logs? If the compilation error happens before the fatalsToBrowser were compiled, the error doesn't go to the browser.

    "\n" just adds a newline. If there was no newline on the preceding line, it doesn't create a blank line. You need two newlines for that.

    print 'first line'; print "\n"; print 'second line'; print "\n\n"; print 'fourth line';
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      I am assuming that this code compiles and resides in memory and each time an error or warn is captured it is sent through carpout to be printed. So if I put print "\n\n"; after the carpout call, it should insert a blank line. However, based on the next monk response, carpout does not work that way and output the whole black of error in one shot and the blank is added befor eor after the block depending location of the \n\n code.

        So if I put print "\n\n"; after the carpout call, it should insert a blank line.

        What in the documentation for carpout supports that idea? More doc, less assuming!

        Since the BEGIN block is executed at the beginning only, as explained in its documentation, maybe what you are thinking of is a custom sig handler for warn?


        The way forward always starts with a minimal test.
      You said: Have you checked your server logs? If the compilation error happens before the fatalsToBrowser were compiled, the error doesn't go to the browser. I ust checked server logs and nothing there. Not even stuff that was reported in my own error log. Will this block intercept errors and prevent them from reaching the regular server log?
Re: Error Log Files
by 1nickt (Canon) on Mar 07, 2017 at 14:38 UTC

    Trying to help you think clearly ... I am just wondering if you could explain why you think you need:

    my $blank = " "; ... print LOG $blank . "\n";
    to get a blank line of output?

    And also why you think that printing one blank line to the log in a BEGIN block will do anything more than print one blank line to the log when the BEGIN block is executed?

    Hope this helps!


    The way forward always starts with a minimal test.
      And also why you think that printing one blank line to the log in a BEGIN block will do anything more than print one blank line to the log when the BEGIN block is executed? I was assuming that each time an error was posted from carp it would also post the blank lin. Wrong assumption.