如何禁用特定类的 Log4perl 输出?
我想在项目中使用 Log4perl,但对某个类禁用它(在本例中为 Net::Amazon)。我以为这会是一件容易的事,但不知何故我失败了。
我尝试使用
use Log::Log4perl (:easy_init);
use Net::Amazon;
my $amz = Net::Amazon->new( ... );
my $log = Log::Log4perl->easy_init($DEBUG);
$log = $log->get_logger("Net::Amazon");
$log->level($OFF);
$log = $log->get_logger(__PACKAGE__);
$log->info("Hello World.");
不幸的是,Net::Amazon 的调试消息仍然打印到终端。这是为什么?我在这里做错了什么?
I would like to use Log4perl in a project but disable it for a certain class (which is, in this case Net::Amazon). I thought this would be an easy one, but somehow I failed.
I tried using
use Log::Log4perl (:easy_init);
use Net::Amazon;
my $amz = Net::Amazon->new( ... );
my $log = Log::Log4perl->easy_init($DEBUG);
$log = $log->get_logger("Net::Amazon");
$log->level($OFF);
$log = $log->get_logger(__PACKAGE__);
$log->info("Hello World.");
Unfortunately, debugging messages of Net::Amazon are still printed to the terminal. Why is that? And what am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你的意思是
I think you mean
问题解决了,是人类的愚蠢造成的。使用 get_logger 获取当前包的记录器后忘记保存它。以下示例按预期工作:
Problem solved, caused by human stupidity. Forgot to save the logger for the current package after getting it with get_logger. The following example works as expected: