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
?
You should probably take a look at some of the formal logging packages for Perl, like log4perl . Undoubtedly, there are others as well.
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");
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.