如何在Log4perl中抑制对stdout和stderr的输出?
我使用此sub来初始化我的记录器:如何在Log4perl中抑制对stdout和stderr的输出?,perl,stdout,log4perl,Perl,Stdout,Log4perl,我使用此sub来初始化我的记录器: sub initLogfiles{ Log::Log4perl->easy_init($INFO); # We log all debug, info, warn, error and fatal messages. my $userlogappender = Log::Log4perl::Appender->new( "Log::Log4perl::Appender::File", file
sub initLogfiles{
Log::Log4perl->easy_init($INFO); # We log all debug, info, warn, error and fatal messages.
my $userlogappender = Log::Log4perl::Appender->new(
"Log::Log4perl::Appender::File",
filename => USERLOGFILE,
mode => "append",
recreate => 1
);
my $userloglayout = Log::Log4perl::Layout::PatternLayout->new("%d;%m%n");
$userlogappender->layout($userloglayout);
$userlogger->add_appender($userlogappender);
}
我只想在我的日志文件中有loginfo。
如何防止此日志记录到标准输出 Log::Log4perl->easy_init()使用ScreenAppender初始化库,这就是日志被发送到stdout的原因
删除它并添加以下内容以将所有日志(调试级别及以上)写入文件:
我找到了。
我必须将此行添加到我的sub:
$userlogger->additivity(0);
我在这里找到了答案:我也在想同样的问题,就在log4j中。我认为这在我的代码中并不好。我使用调试级别,所以设置阈值来阻止调试是不行的。但是谢谢你的回答。我忘了提到easy_init()调用必须被删除;这并不能阻止调试。不管怎样,如果additivity()起到了作用,那就好了。
$userlogger->additivity(0);