From: Mike S. <m...@pe...> - 2004-06-06 19:55:16
|
I've checked in the changes for the global cleanup. There's still one open issue, but it can be tackled another time: Added a cleanup() function to Logger.pm which is used by an END {} block in Logger.pm to tear down all Loggers/Appenders before global destruction kicks in. There's still a problem with a leftover reference to a L4p::Appender object, which you can see if you set $Log::Log4perl::CHATTY_DESTROY_METHODS to 1. The "meat" is cleaned up by the cleanup function, calling its DESTROY() method, though. However, there's still another call to DESTROY() during the GDP. Kevin's idea is in now, on localizing $? in the L4p global END {} block. It prevents logdie() et. al from exiting with unwanted exit codes when global cleanup / global destruction modifies $?, as seen by Tim with the Email appender. Here's the diff: Index: Changes =================================================================== RCS file: /cvsroot/log4perl/Log-Log4perl/Changes,v retrieving revision 1.186 diff -a -u -r1.186 Changes --- Changes 28 May 2004 23:41:53 -0000 1.186 +++ Changes 6 Jun 2004 19:45:33 -0000 @@ -5,6 +5,18 @@ 0.46 (not yet released) * (ms) removed superfluous eval() in Log4perl.pm, reported anonymously on the CPAN bugtracker. + * (ms) Added a cleanup() function to Logger.pm which is used by an + END {} block in Logger.pm to tear down all Loggers/Appenders + before global destruction kicks in. There's still a problem with + a leftover reference to a L4p::Appender object, which you can + see if you set $Log::Log4perl::CHATTY_DESTROY_METHODS to 1. The + "meat" is cleaned up by the cleanup function, calling its DESTROY() + method, though. However, there's still another call to DESTROY() + during the GDP. + * (ms) Kevin's idea is in now, on localizing $? in the L4p global END {} + block. It prevents logdie() et. al from exiting with unwanted + exit codes when global cleanup / global destruction modifies $?, + as seen by Tim with the Email appender. 0.45 (05/23/2004) * (ms) fix for t/045Composite.t on perl 5.6.1 by Jeff Macdonald Index: lib/Log/Log4perl.pm =================================================================== RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl.pm,v retrieving revision 1.164 diff -a -u -r1.164 Log4perl.pm --- lib/Log/Log4perl.pm 28 May 2004 23:41:54 -0000 1.164 +++ lib/Log/Log4perl.pm 6 Jun 2004 19:45:36 -0000 @@ -2,6 +2,9 @@ package Log::Log4perl; ################################################## + # Have this first to execute last +END { local($?); Log::Log4perl::Logger::cleanup(); } + use 5.006; use strict; use warnings; @@ -57,6 +60,8 @@ #and XML Config unit tests our $DOM_VERSION_REQUIRED = '1.29'; +our $CHATTY_DESTROY_METHODS = 0; + ################################################## sub import { ################################################## Index: lib/Log/Log4perl/Appender.pm =================================================================== RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Appender.pm,v retrieving revision 1.35 diff -a -u -r1.35 Appender.pm --- lib/Log/Log4perl/Appender.pm 26 Apr 2004 02:41:10 -0000 1.35 +++ lib/Log/Log4perl/Appender.pm 6 Jun 2004 19:45:37 -0000 @@ -260,7 +260,11 @@ ################################################## sub DESTROY { ################################################## - # just there because of AUTOLOAD + warn "Destroying appender $_[0]" if $Log::Log4perl::CHATTY_DESTROY_METHODS; + + foreach my $key (keys %{$_[0]}) { + delete $_[0]->{$key}; + } } 1; Index: lib/Log/Log4perl/Logger.pm =================================================================== RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Logger.pm,v retrieving revision 1.60 diff -a -u -r1.60 Logger.pm --- lib/Log/Log4perl/Logger.pm 9 Oct 2003 17:07:11 -0000 1.60 +++ lib/Log/Log4perl/Logger.pm 6 Jun 2004 19:45:38 -0000 @@ -23,6 +23,44 @@ __PACKAGE__->reset(); ################################################## +sub cleanup { +################################################## + # warn "Logger cleanup"; + + # Delete all loggers + foreach my $loggername (keys %$LOGGERS_BY_NAME){ + # warn "Logger delete: $loggername"; + $LOGGERS_BY_NAME->{$loggername}->DESTROY(); + delete $LOGGERS_BY_NAME->{$loggername}; + } + + # Delete the root logger + undef $ROOT_LOGGER; + + # Delete all appenders + foreach my $appendername (keys %APPENDER_BY_NAME){ + if (exists $APPENDER_BY_NAME{$appendername} && + exists $APPENDER_BY_NAME{$appendername}->{appender}) { + # Destroy L4p::Appender + $APPENDER_BY_NAME{$appendername}->DESTROY(); + delete $APPENDER_BY_NAME{$appendername}->{appender}; + } + delete $APPENDER_BY_NAME{$appendername}; + } + %APPENDER_BY_NAME = (); +} + +################################################## +sub DESTROY { +################################################## + warn "Destroying logger $_[0]" if $Log::Log4perl::CHATTY_DESTROY_METHODS; + + for(keys %{$_[0]}) { + delete $_[0]->{$_}; + } +} + +################################################## sub reset { ################################################## $ROOT_LOGGER = __PACKAGE__->_new("", $DEBUG); -- -- Mike Mike Schilli m...@pe... |