|
From: Gordon M. <gm...@gm...> - 2003-06-03 17:12:58
|
Thanks for the advice - I'll take it to heart and make the recommended
change in #1 at the very least.
Note that in trying to simplify this issue, I eventually remove the
"Class" attributes hash %BE (defined as "our %BE"). I use this to try
to keep track of several things related to this application, such as:
1. Total number of BE object instances
2. Config data that is global
Seems that if I remove this entirely, the DESTROY problem disappears.
I'll look into this more after I implement your suggested changes.
Gordon
On Tue, 2003-06-03 at 13:25, Mike Schilli wrote:
> 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
--
Gordon Marler <gm...@gm...>
|