- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Log4perl 的新手,我想弄清楚为什么我在下面的设置中得到了两个不同的记录器。我的理解是这应该是一个单例并且调用 get_logger() 每次都会返回相同的对象实例。
测试.pm
#!/usr/bin/perl
package Example::Test;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(test);
sub test
{
my $logger = Log::Log4perl->get_logger();
print $logger, "\n";
}
#!/usr/bin/perl
use strict;
use warnings;
use Log::Log4perl;
use Example::Test;
# Logger configuration
Log::Log4perl->init('/etc/log4perl.conf');
my $logger = Log::Log4perl->get_logger();
print $logger, "\n";
my $engine = test();
Log::Log4perl::Logger=HASH(0x12093d0)
Log::Log4perl::Logger=HASH(0x29b4950)
最佳答案
您没有指定日志记录类别,因此您的代码相当于
Log::Log4perl->get_logger(__PACKAGE__);
__PACKAGE__
是
Example::Test
在你的模块和
main
在你的脚本里面。
Categories are also called "Loggers" in Log4perl, both refer to the same thing and these terms are used interchangeably.
Log::Log4perl
uses categories to determine if a log statement in a component should be executed or suppressed at the current logging level. Most of the time, these categories are just the classes the log statements are located in...
Example::Test
应该是 Log::Log4perl 的包装器,
register it :
package My::Wrapper;
use strict;
use warnings 'all';
use 5.010;
use Log::Log4perl;
Log::Log4perl->wrapper_register(__PACKAGE__);
sub foo {
my $logger = Log::Log4perl->get_logger;
say $logger;
$logger->warn('foo');
}
1;
My::Wrapper::foo()
来自包装
main
,日志记录类别将为
main::
.
关于perl - Log4perl 单例使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407990/
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!