From: Mike S. <log...@pe...> - 2003-06-03 17:09:34
|
On Tue, 3 Jun 2003, Gordon Marler wrote: > I noticed that the Log4perl was pretty much a singleton pattern a while > back, so my object's constructor looks like this: > ... > # Constructor > sub new { > ... > unless (BE->logger) { > Log::Log4perl::init_and_watch('/usr/LBBE/bootdiskmanager/bin/log.conf',10); > my $logger = Log::Log4perl->get_logger('BE'); > BE->logger($logger); > } > $logger = Log::Log4perl->get_logger('BE'); > ... > $instance->{_logger} = $logger; I see two problems with this approach: 1) As mentioned in my previous post, Log::Log4perl->init() (or init_and_watch) should only be called in the main program, not in libraries or classes. Reason for this is that there can (currently) only be *one* configuration file. If you call Log::Log4perl->init() multiple times (what you will do implicitely if someone else doesn't comply with this Log4perl mandate either), the last call to init() will overwrite all previous settings. Bottom line: Log::Log4perl->init() (or init_and_watch) should only be called in the main program. 2) my $logger = Log::Log4perl->get_logger('BE'); will always return a reference to the *same* object, no matter how often you call it or which class/object instance you're calling it from. This instance should *never* be stored anywhere or deleted. Always retrieve them via get_logger(). 3) Your particular problem seems to be related with the way your accessors work, I haven't tracked it down yet entirely, but it works with "regular" instance variables. Tonight, I'm gonna look into it again, but it shouldn't be relevant because you can fix the problem by fixing 1) and 2). -- Mike Mike Schilli log...@pe... http://perlmeister.com http://log4perl.sourceforge.net |