开发者

How do I make my Log::Log4perl logger work?

Here's the code I have:

use strict;
use warnings;
use Log::Log4perl qw(:easy);

Log::Log4perl->init({
 level => $DEBUG
});

my $logger = Log::Log4perl->get_logger("my.logger");
my $appender = Log::Log4perl::Appender->new("Log::Log4perl::Appender::File",filename => "my.file");
$appender->layout(Log::Log4perl::Layout::SimpleLayout->new);
$logger->add_appender($appender);

$logger->info("this is an info");

all I want to do is log a message to a file, and have the level show up. I understood that is what the SimpleLayout is for . I'd like to do this开发者_StackOverflow中文版 without a configuration file. Running the code above shows the following message:

Log::Log4perl configuration looks suspicious: No loggers defined


From http://log4perl.sourceforge.net/releases/Log-Log4perl/docs/html/Log/Log4perl/FAQ.html#f625e , try this approach:

use Log::Log4perl qw(:easy);
# Append to a log file
Log::Log4perl->easy_init( { level   => $DEBUG,
                            file    => ">>my.file" } );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜