Reputation: 11266
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
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
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
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