in reply to log4perl in module appending to callers log file

may be you are missing to call get_logger in the main script. try this one:
use strict; use warnings; use Log::Log4perl; my $logging_level = 'DEBUG'; my $conf = q( + log4perl.rootLogger = ).$logging_level.q(, logApp log4perl.appender.logApp = Log::Log4perl::Appender::File + log4perl.appender.logApp.mode = append log4perl.appender.logApp.filename = 917173_test.log + log4perl.appender.logApp.layout = Log::Log4perl::Layout::P +atternLayout log4perl.appender.logApp.layout.ConversionPattern = %m % +n ); Log::Log4perl->init( \$conf ); + my $logger = Log::Log4perl->get_logger(); $logger->info("outer"); testPackage::foo(); $logger->info("outer"); package testPackage; use Log::Log4perl qw(get_logger); sub foo { my $logger = Log::Log4perl->get_logger(); # IF I PUT testLog IN T +HE QUOTES THEN I'M GETTING THE blah IN THE CALLERS LOGS FILE $logger->info("inner"); } 1;
this produces following output:
outer inner outer

Replies are listed 'Best First'.
Re^2: log4perl in module appending to callers log file
by GB (Initiate) on Jul 28, 2011 at 14:49 UTC
    Thanks for the reply. I wanted this behavior where called module logs to the caller script's appenders. The only logical difference I see from your code is that you have used rootLogger and I've used my logger.testLog. I'm also calling get_logger in the module but looks like calling get_logger("") in the module writes to rootLogger and not custom logger.

    And so I was not able to get the logs from the called module into the caller appenders.

    Do you know if there is any other way If I don't use the rootLogger and also doesn't specify the target logger name in the called module?
      I'm not a guru but this is a way I used Log4Perl. I don't know a reference but I think there is a logging hierarchy in other words there is a parent logger where all other logger depend on. And the logger on the top is a root logger. Maybe called modules look for this specific logger where they can append to. This config works fine for me so I don't care much about the thing behind it...