0

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 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

You code looks good but it doesn't work either... and I can't find out any useful information from error_log. I suspect opening file has failed, but where and how to check the content of $!?
0

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.