开发者

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

开发者 https://www.devze.com 2022-12-31 12:55 出处:网络
Here\'s the code I have: use strict; use warnings; use Log::Log4perl qw(:easy); Log::Log4perl->init({ level => $DEBUG

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

精彩评论

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

关注公众号