My Perl application (in BlueHost hosting) is generating some errors. This error can be shown in the Main Error Log of BlueHost (which is shared):

/var/log/domlogs/error_log

I don't understand how my errors appears in that file, because in my code I am not referencing it anywhere. How does this process works? Is there any way to avoid my errors appear in that file?

有帮助吗?

解决方案

You can redirect STDERR yourself without needing an external module:

use strict;
use warnings;
use autodie;

BEGIN {
    open my $fh, '>>', 'myerror.log';
    close STDERR;
    *STDERR = $fh;
}

warn "Hello world";

die "Bye world";

The above script closes the default STDERR and opens my own. It waits to close until after the open command is called just in case there is some error with the file we're trying to log to.

Log file will report:

Hello world at scratch.pl line 11.
Bye world at scratch.pl line 13.

其他提示

This line solved my problem:

use Tie::STDERR '>> /home/user/public_html/project/log/error_log.log';

I had to install the perl module:

Tie:STDERR

Information taken from: http://www.adelton.com/perl/Tie-STDERR/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top