[英]How can you output Error messages to a different logfile?
In Perl you can: 在Perl中你可以:
print STDERR "bla bla bla";
...and Apache will dump it to /etc/httpd/logs/error_log
. ...并且Apache会将其转储到
/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? 如何在Perl中创建一个函数来执行此操作?
print MYLOGFILE "bla bla bla"
...to render to /logs/my_favorite_log
? ...渲染到
/logs/my_favorite_log
?
Use Log::Trivial 使用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. 我建议按照Will的建议查看Log :: Log4perl 。 There is good introduction tutorial available .
有很好的介绍教程 。
For small scripts there is also quick setup with easy mode . 对于小脚本,还可以使用简易模式快速设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.