From: Gordon M. <gm...@gm...> - 2003-06-03 14:27:06
|
I've been using Log::Log4perl for several months now, with great success - great job! I've designed my Perl object to contain a reference to a Log::Log4perl object, and this seems to work for all methods in the object except DESTROY. Here's an example of what my DESTROY method looks like (the name of my object and it's package is "BE"): sub DESTROY { my ($self) = @_; my ($logger) = Log::Log4perl->get_logger("BE"); $logger->info("Entering DESTROY method for " . __PACKAGE__ . "\n"); } However, when my script ends, I get the following error message as the DESTROY method of my object gets called: (in cleanup) Can't call method "log" on an undefined value at (eval 271) line 42 during global destruction. Since I'm keeping a reference to the Log::Log4perl object inside my object, I'm curious as to why the Log::Log4perl object is getting destroyed before my object enters the DESTROY method. Just to check, I used Data::Dumper to print the state of the object while entering other methods, and then when entering the DESTROY method - note the difference: Upon entering any normal method: $VAR1 = bless( { '_diskgroup' => 'rootdg', '_logger' => bless( { 'DEBUG' => sub { "DUMMY" }, 'additivity' => 1, 'ALL' => sub { "DUMMY" }, 'appender_names' => [ 'ConsoleAppndr', 'FileAppndr2' ], 'FATAL' => $VAR1->{'_logger'}{'DEBUG'}, 'ERROR' => $VAR1->{'_logger'}{'DEBUG'}, 'WARN' => $VAR1->{'_logger'}{'DEBUG'}, 'INFO' => $VAR1->{'_logger'}{'DEBUG'}, 'level' => 10000, 'layout' => undef, 'category' => 'BE', 'num_appenders' => 14, 'OFF' => $VAR1->{'_logger'}{'DEBUG'} }, 'Log::Log4perl::Logger' ), '_mountpoint' => '/.lbbe.orig', '_bootable' => '1', '_complete' => '1', '_filesystems' => { '/' => [ 'rootvol', 'c0t0d0s0' ] }, '_device' => 'c0t0d0', '_name' => 'orig', '_creation' => undef, '_dgid' => '1038429905.1025.ns3' }, 'BE' ); Upon entering the DESTROY method: $VAR1 = bless( { '_diskgroup' => 'rootdg', '_logger' => undef, '_mountpoint' => '/.lbbe.orig', '_bootable' => '1', '_complete' => '1', '_filesystems' => { '/' => [ 'rootvol', 'c0t0d0s0' ] }, '_device' => 'c0t0d0', '_name' => 'orig', '_creation' => undef, '_dgid' => '1038429905.1025.ns3' }, 'BE' ); Note how _logger is now undef. Any ideas on how to work around this problem? I'd rather not resort to just using print() inside the DESTROY method. -- Gordon Marler <gm...@gm...> |