Вопрос

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