-1

I wrote a class A where I define and initialize a rootlogger

my $conf = q(
          log4perl.rootLogger = ERROR, LOGFILE   
          log4perl.appender.LOGFILE.filename = /var/log/Application.log
          log4perl.appender.LOGFILE = Log::Log4perl::Appender::File
          log4perl.appender.LOGFILE.mode = write  
          log4perl.appender.LOGFILE.layout = PatternLayout
          log4perl.appender.LOGFILE.layout.ConversionPattern = [%r] %F %L %c - %m%n
          );
Log::Log4perl->init(\$conf);

In a subclass of A I want to use this logger

$self->LOG(Log::Log4perl->get_logger("Hotels"));
$self->LOG()->info("Starting 'Hotels'");

When running the application I get the message

Log4perl: Seems like no initialization happened. Forgot to call init()?

Why is the init not recognized?

K.D.J.

kdjantzen
  • 1
  • 1
  • Please show all the code http://stackoverflow.com/help/mcve. Things get a little mysterious as you have shown so little. One issue is that you are using info but only showing errors in your config. – Dan Walmsley Aug 25 '16 at 23:40

1 Answers1

1

Your example lacks enough detail for me to understand what is going on.

But here is an example that works.

use strict;
use warnings;
use Log::Log4perl;


my $conf = q(
          log4perl.rootLogger = ERROR, LOGFILE   
          log4perl.appender.LOGFILE.filename = /tmp/Application.log
          log4perl.appender.LOGFILE = Log::Log4perl::Appender::File
          log4perl.appender.LOGFILE.mode = write  
          log4perl.appender.LOGFILE.layout = PatternLayout
          log4perl.appender.LOGFILE.layout.ConversionPattern = [%r] %F %L %c - %m%n
          );
Log::Log4perl->init(\$conf);

my $logger = Log::Log4perl->get_logger("Hotels");

$logger->error("test");
Dan Walmsley
  • 2,765
  • 7
  • 26
  • 45