Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 782
qodeninja Avatar asked Nov 25 '25 12:11

qodeninja


2 Answers

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

like image 68
Will Hartung Avatar answered Nov 28 '25 15:11

Will Hartung


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");
like image 28
yb007 Avatar answered Nov 28 '25 15:11

yb007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!