Skip to content

Commit

Permalink
PAXLOGGING-140: Ensure Appender resources get released on bundle rest…
Browse files Browse the repository at this point in the history
…art/refresh
  • Loading branch information
gertv committed May 15, 2012
1 parent 29c27a7 commit 290b2cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Activator
/**
* Reference to the registered service
*/
private PaxLoggingServiceImpl m_PaxLogging;
private ServiceRegistration m_RegistrationPaxLogging;
private JdkHandler m_JdkHandler;
private ServiceRegistration m_registrationLogReaderService;
Expand Down Expand Up @@ -105,11 +106,11 @@ public void destroy()
}

// register the Pax Logging service
PaxLoggingServiceImpl paxLogging = new PaxLoggingServiceImpl( bundleContext, logReader, m_eventAdmin );
m_PaxLogging = new PaxLoggingServiceImpl( bundleContext, logReader, m_eventAdmin );
Hashtable serviceProperties = new Hashtable();
serviceProperties.put( Constants.SERVICE_ID, "org.ops4j.pax.logging.configuration" );
serviceProperties.put( Constants.SERVICE_PID, CONFIGURATION_PID );
m_RegistrationPaxLogging = bundleContext.registerService( LOGSERVICE_NAMES, paxLogging, serviceProperties );
m_RegistrationPaxLogging = bundleContext.registerService( LOGSERVICE_NAMES, m_PaxLogging, serviceProperties );

// Add a global handler for all JDK Logging (java.util.logging).
String skipJULProperty=bundleContext.getProperty("org.ops4j.pax.logging.skipJUL");
Expand All @@ -127,10 +128,10 @@ public void destroy()

rootLogger.setFilter(null);

m_JdkHandler = new JdkHandler( paxLogging );
m_JdkHandler = new JdkHandler( m_PaxLogging );
rootLogger.addHandler( m_JdkHandler );
}
m_frameworkHandler = new FrameworkHandler( paxLogging );
m_frameworkHandler = new FrameworkHandler( m_PaxLogging );
bundleContext.addBundleListener( m_frameworkHandler );
bundleContext.addFrameworkListener( m_frameworkHandler );
bundleContext.addServiceListener( m_frameworkHandler );
Expand Down Expand Up @@ -163,6 +164,12 @@ public void stop( BundleContext bundleContext )
m_RegistrationPaxLogging.unregister();
m_RegistrationPaxLogging = null;

// Shutdown Pax Logging to ensure appender file locks get released
if (m_PaxLogging != null) {
m_PaxLogging.shutdown();
m_PaxLogging = null;
}

m_registrationLogReaderService.unregister();
m_registrationLogReaderService = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PaxLoggingConfigurator;
Expand Down Expand Up @@ -65,6 +66,14 @@ public PaxLoggingServiceImpl( BundleContext context, LogReaderServiceImpl logRea
configureDefaults();
}

/**
* Shut down the Pax Logging service. This will reset the logging configuration entirely, so it should only be
* used just before disposing of the service instance.
*/
protected void shutdown() {
LogManager.resetConfiguration();
}

ReadWriteLock getConfigLock() {
return m_configLock;
}
Expand Down

0 comments on commit 290b2cd

Please sign in to comment.