in reply to Re^2: Can't call method on an undefined value
in thread Can't call method on an undefined value
cpan's log4perlsays "You can get a logger anytime via a singleton mechanism:".
I think you can reproduce your situation if you make simple example codes. I am not sure about relation between main package and foo/bar/baz packages,especially. Readmore tag seems to be recommended for a sample code which becomes long, I put them below.
logger.conf is like this.. ./logger.conf ./test.log ./main.pl ./subdir ./subdir/Foo.pm ./subdir/Bar.pm ./subdir/Baz.pm
And Foo/Bar/Baz.pm are the same file############################################################ # A simple root logger with a Log::Log4perl::Appender::File # file appender in Perl. ############################################################ #log4perl.rootLogger=ERROR, LOGFILE log4perl.rootLogger=DEBUG, LOGFILE log4perl.appender.LOGFILE=Log::Log4perl::Appender::File log4perl.appender.LOGFILE.filename=test.log log4perl.appender.LOGFILE.mode=append log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m% +n
And I couldn't have idea of what your main.pl looks like. May be your main.pl will not be like this... I wonder if you show what it is like, you will get more clue or hints.package subdir::Foo; sub test{ print "#inc=@INC#"; my $log = Log::Log4perl->get_logger("MyMain"); $log->debug("Here is a debug message in ". __PACKAGE__ ); } 1;
If you click button, you will see test.log with these messages.use strict; use warnings; use Gtk2 -init; MyMain::test(); { package MyMain; sub test{ use Log::Log4perl; Log::Log4perl::init_and_watch( 'logger.conf', 30 ); my $logger = Log::Log4perl->get_logger; # Run main loop. $logger->debug("before gtk"); my $win = Gtk2::Window->new; my $b1= Gtk2::Button->new("test 1"); $b1->signal_connect(clicked => sub{ use subdir::Foo; subdir::Foo::test(); use subdir::Bar; subdir::Bar::test(); use subdir::Baz; subdir::Baz::test(); my $log = Log::Log4perl->get_logger("MyMain"); $log->debug("after get_logger in MyMain ...quit"); Gtk2->main_quit; }); $win->add ($b1); $win->show_all; #main loop Gtk2->main; } 1; }
[1] main.pl 18 MyMain - before gtk [2466] subdir/Foo.pm 6 MyMain - Here is a debug message in subdir::Foo [2466] subdir/Bar.pm 6 MyMain - Here is a debug message in subdir::Bar [2466] subdir/Baz.pm 6 MyMain - Here is a debug message in subdir::Baz [2467] main.pl 32 MyMain - after get_logger in MyMain ...quit
|
---|