문제

I want to add some logs to my CGI scripts with Perl code like this:

open(LOG, ">/path/to/my.log") or die;
print LOG "Some content...\n";
close(LOG);

However, logs are never written to my log file, while the scripts are still correctly handling requests.

I'm not very familiar with Apache, CGI and Perl, so gurus please shine a light.

도움이 되었습니까?

해결책 2

The problem has been solved: changes to my Perl script take effect only after restarting Apache. Not sure why it behaves like this because I am thinking Perl is an interpreted language and it can be modified on the fly...

다른 팁

It is probably a permission problem. The script's runner (probably user: apache, httpd or nobody) has no permission to write to the file. However, to be sure, you need to check what $! contains. Also try checking Apache's ErrorLog file when the script is run.

I would rewrite your code as:

use CGI::Carp qw( croak );

open my $log, '>', '/path/to/my.log' or croak "Error opening file: $!";
print $log "Some content...\n";
close $log;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top