FELIX-3016 Activator.log should also obey dynamically configured log level
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1344808 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 2494608..5b4961a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -49,10 +49,7 @@
static final String PACKAGEADMIN_CLASS = "org.osgi.service.packageadmin.PackageAdmin";
// Our configuration from bundle context properties and Config Admin
- private ScrConfiguration m_configuration;
-
- // Flag that sets error messages
- private static int m_logLevel = LogService.LOG_DEBUG;
+ private static ScrConfiguration m_configuration = new ScrConfiguration();
// this bundle's context
private static BundleContext m_context;
@@ -96,10 +93,7 @@
m_componentRegistry = new ComponentRegistry( context );
// get the configuration
- m_configuration = new ScrConfiguration( context );
-
- // configure logging from context properties
- m_logLevel = m_configuration.getLogLevel();
+ m_configuration.start( context );
// log SCR startup
log( LogService.LOG_INFO, context.getBundle(), " Version = "
@@ -386,7 +380,7 @@
*/
public static void log( int level, Bundle bundle, String message, Throwable ex )
{
- if ( m_logLevel >= level )
+ if ( m_configuration.getLogLevel() >= level )
{
Object logger = ( m_logService != null ) ? m_logService.getService() : null;
if ( logger == null )
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
index a988a70..018cc7f 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
@@ -25,6 +25,7 @@
import org.apache.felix.scr.impl.Activator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
@@ -78,19 +79,26 @@
private static final String PROP_SHOWERRORS = "ds.showerrors";
- private final BundleContext bundleContext;
-
private int logLevel;
private boolean factoryEnabled;
private boolean keepInstances;
- public ScrConfiguration( BundleContext bundleContext )
+ private BundleContext bundleContext;
+
+ private ServiceRegistration managedService;
+
+ public ScrConfiguration( )
{
+ // default configuration
+ configure( null );
+ }
+
+ public void start(final BundleContext bundleContext){
this.bundleContext = bundleContext;
- // default configuration
+ // reconfigure from bundle context properties
configure( null );
// listen for Configuration Admin configuration
@@ -102,14 +110,32 @@
props);
}
+ public void stop() {
+ if (this.managedService != null) {
+ this.managedService.unregister();
+ this.managedService = null;
+ }
+
+ this.bundleContext = null;
+ }
+
// Called from the ScrManagedService.updated method to reconfigure
void configure( Dictionary config )
{
if ( config == null )
{
- logLevel = getDefaultLogLevel();
- factoryEnabled = getDefaultFactoryEnabled();
- keepInstances = getDefaultKeepInstances();
+ if ( this.bundleContext == null )
+ {
+ logLevel = LogService.LOG_ERROR;
+ factoryEnabled = false;
+ keepInstances = false;
+ }
+ else
+ {
+ logLevel = getDefaultLogLevel();
+ factoryEnabled = getDefaultFactoryEnabled();
+ keepInstances = getDefaultKeepInstances();
+ }
}
else
{