简体   繁体   English

如何将错误消息输出到其他日志文件?

[英]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

You should probably take a look at some of the formal logging packages for Perl, like log4perl . 你应该看一下Perl的一些正式的日志包,比如log4perl Undoubtedly, there are others as well. 毫无疑问,还有其他人。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM