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.

Suppose there are these files.
. ./logger.conf ./test.log ./main.pl ./subdir ./subdir/Foo.pm ./subdir/Bar.pm ./subdir/Baz.pm
logger.conf is like this.
############################################################ # 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 Foo/Bar/Baz.pm are the same file
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;
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.
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; }
If you click button, you will see test.log with these messages.
[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
regards

In reply to Re^3: Can't call method on an undefined value by remiah
in thread Can't call method on an undefined value by Zettai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.