qodeninja
qodeninja

Reputation: 11266

How can you output Error messages to a different logfile?

In Perl you can:

print STDERR "bla bla bla"; 

...and Apache will dump it to /etc/httpd/logs/error_log.

But what if I want to send some error/warning messages to a different log file?

How can I create a function to do this in Perl?

print MYLOGFILE "bla bla bla"

...to render to /logs/my_favorite_log?

Upvotes: 2

Views: 204

Answers (3)

bvr
bvr

Reputation: 9697

I would recommend looking at Log::Log4perl, as suggested by Will. There is good introduction tutorial available.

For small scripts there is also quick setup with easy mode.

Upvotes: 4

yb007
yb007

Reputation: 1377

Use Log::Trivial

use Log::Trivial;
my $logfile = Log::Trivial->new(log_file => "logs/my_favourite.log");
$logfile->set_level(3);
$logfile->write(comment => "bla bla bla");

Upvotes: 5

Will Hartung
Will Hartung

Reputation: 118641

You should probably take a look at some of the formal logging packages for Perl, like log4perl. Undoubtedly, there are others as well.

Upvotes: 7

Related Questions