You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2010/12/09 09:12:03 UTC
svn commit: r1043855 - in /sling/trunk/bundles/commons/log: ./
src/main/java/org/apache/sling/commons/log/internal/
src/main/java/org/apache/sling/commons/log/internal/config/
src/main/java/org/apache/sling/commons/log/internal/slf4j/
Author: fmeschbe
Date: Thu Dec 9 08:12:02 2010
New Revision: 1043855
URL: http://svn.apache.org/viewvc?rev=1043855&view=rev
Log:
SLING-1482 Encapsulate Configuration Admin support to (a) not require Configuration Admin API to operate and (b) not export Configuration Admin API
CAUTION: This is largely untested
Added:
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java (with props)
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java (with props)
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java (with props)
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java (with props)
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java (with props)
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java (with props)
Modified:
sling/trunk/bundles/commons/log/pom.xml
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/LogConfigManager.java
Modified: sling/trunk/bundles/commons/log/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/pom.xml?rev=1043855&r1=1043854&r2=1043855&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/pom.xml (original)
+++ sling/trunk/bundles/commons/log/pom.xml Thu Dec 9 08:12:02 2010
@@ -67,7 +67,7 @@
org.apache.commons.logging;version=1.1.1,
org.apache.log4j;version=1.2.15,
org.slf4j;version=${slf4j.version},
- org.osgi.service.cm, org.osgi.service.log
+ org.osgi.service.log
</Export-Package>
<Private-Package>
org.apache.commons.logging.impl,
@@ -77,9 +77,11 @@
</Private-Package>
<Import-Package>
javax.servlet.*;resolution:=optional,
- org.osgi.framework;version=1.3,
- *
+ org.osgi.framework;version=1.3
</Import-Package>
+ <DynamicImport-Package>
+ org.osgi.service.cm
+ </DynamicImport-Package>
</instructions>
</configuration>
</plugin>
Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java?rev=1043855&r1=1043854&r2=1043855&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java (original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java Thu Dec 9 08:12:02 2010
@@ -19,15 +19,13 @@ package org.apache.sling.commons.log.int
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.sling.commons.log.internal.config.ConfigurationServiceFactory;
import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
import org.apache.sling.commons.log.internal.slf4j.SlingConfigurationPrinter;
import org.apache.sling.commons.log.internal.slf4j.SlingLogPanel;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.cm.ManagedServiceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -76,17 +74,12 @@ public class LogManager {
private ServiceRegistration configConfigurer;
- LogManager(final BundleContext context) throws ConfigurationException {
+ LogManager(final BundleContext context) {
// set the root folder for relative log file names
logConfigManager = LogConfigManager.getInstance();
logConfigManager.setRoot(context.getProperty("sling.home"));
-
- // Global configuration handler and update this configuration
- // immediately
- ManagedService globalConfigurator = new GlobalConfigurator(
- logConfigManager, getBundleConfiguration(context));
- globalConfigurator.updated(null);
+ logConfigManager.setDefaultConfiguration(getBundleConfiguration(context));
// get our own logger
log = LoggerFactory.getLogger(LogServiceFactory.class);
@@ -101,22 +94,28 @@ public class LogManager {
props.put(Constants.SERVICE_DESCRIPTION,
"LogManager Configuration Admin support");
loggingConfigurable = context.registerService(
- ManagedService.class.getName(), globalConfigurator, props);
+ "org.osgi.service.cm.ManagedService",
+ new ConfigurationServiceFactory(logConfigManager,
+ "org.apache.sling.commons.log.internal.config.GlobalConfigurator"),
+ props);
// register for log writer configuration
- ManagedServiceFactory msf = new LogWriterManagedServiceFactory(
- logConfigManager);
+ ConfigurationServiceFactory msf = new ConfigurationServiceFactory(
+ logConfigManager,
+ "org.apache.sling.commons.log.internal.config.LogWriterManagedServiceFactory");
props.put(Constants.SERVICE_PID, FACTORY_PID_WRITERS);
- props.put(Constants.SERVICE_DESCRIPTION, msf.getName());
+ props.put(Constants.SERVICE_DESCRIPTION, "LogWriter configurator");
writerConfigurer = context.registerService(
- ManagedServiceFactory.class.getName(), msf, props);
+ "org.osgi.service.cm.ManagedServiceFactory", msf, props);
// register for log configuration
- msf = new LoggerManagedServiceFactory(logConfigManager);
+ msf = new ConfigurationServiceFactory(
+ logConfigManager,
+ "org.apache.sling.commons.log.internal.config.LoggerManagedServiceFactory");
props.put(Constants.SERVICE_PID, FACTORY_PID_CONFIGS);
- props.put(Constants.SERVICE_DESCRIPTION, msf.getName());
+ props.put(Constants.SERVICE_DESCRIPTION, "Logger configurator");
configConfigurer = context.registerService(
- ManagedServiceFactory.class.getName(), msf, props);
+ "org.osgi.service.cm.ManagedServiceFactory", msf, props);
// setup the web console plugin panel. This may fail loading
// the panel class if the Servlet API is not wired
@@ -180,96 +179,4 @@ public class LogManager {
return config;
}
-
- private static class GlobalConfigurator implements ManagedService {
-
- private final LogConfigManager logConfigManager;
-
- private final Dictionary<String, String> defaultConfiguration;
-
- GlobalConfigurator(LogConfigManager logConfigManager,
- Dictionary<String, String> defaultConfiguration) {
- this.logConfigManager = logConfigManager;
- this.defaultConfiguration = defaultConfiguration;
- }
-
- @SuppressWarnings("unchecked")
- public void updated(Dictionary properties)
- throws ConfigurationException { // unchecked
-
- // fallback to start default settings when the config is deleted
- if (properties == null) {
- properties = defaultConfiguration;
- }
-
- // set the logger name to a special value to indicate the global
- // (ROOT) logger setting (SLING-529)
- properties.put(LOG_LOGGERS, LogConfigManager.ROOT);
-
- // update the default log writer and logger configuration
- logConfigManager.updateLogWriter(PID, properties);
- logConfigManager.updateLoggerConfiguration(PID, properties);
- }
-
- }
-
- private static class LogWriterManagedServiceFactory implements
- ManagedServiceFactory {
-
- private final LogConfigManager logConfigManager;
-
- LogWriterManagedServiceFactory(LogConfigManager logConfigManager) {
- this.logConfigManager = logConfigManager;
- }
-
- public String getName() {
- return "LogWriter configurator";
- }
-
- @SuppressWarnings("unchecked")
- public void updated(String pid, Dictionary configuration)
- throws ConfigurationException {
- logConfigManager.updateLogWriter(pid, configuration);
- }
-
- public void deleted(String pid) {
- try {
- logConfigManager.updateLogWriter(pid, null);
- } catch (ConfigurationException ce) {
- // not expected
- LogConfigManager.internalFailure(
- "Unexpected Configuration Problem", ce);
- }
- }
- }
-
- private static class LoggerManagedServiceFactory implements
- ManagedServiceFactory {
-
- private final LogConfigManager logConfigManager;
-
- LoggerManagedServiceFactory(LogConfigManager logConfigManager) {
- this.logConfigManager = logConfigManager;
- }
-
- public String getName() {
- return "Logger configurator";
- }
-
- @SuppressWarnings("unchecked")
- public void updated(String pid, Dictionary configuration)
- throws ConfigurationException {
- logConfigManager.updateLoggerConfiguration(pid, configuration);
- }
-
- public void deleted(String pid) {
- try {
- logConfigManager.updateLoggerConfiguration(pid, null);
- } catch (ConfigurationException ce) {
- // not expected
- LogConfigManager.internalFailure(
- "Unexpected Configuration Problem", ce);
- }
- }
- }
}
Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java?rev=1043855&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java (added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java Thu Dec 9 08:12:02 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.config;
+
+public class ConfigurationException extends Exception {
+
+ private static final long serialVersionUID = -9213226340780391070L;
+
+ private final String property;
+
+ private final String reason;
+
+ public ConfigurationException(final String property, final String reason) {
+ this(property, reason, null);
+ }
+
+ public ConfigurationException(final String property, final String reason,
+ final Throwable cause) {
+ super("", cause);
+ this.property = property;
+ this.reason = reason;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+}
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java?rev=1043855&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java (added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java Thu Dec 9 08:12:02 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.config;
+
+import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class ConfigurationServiceFactory implements ServiceFactory {
+
+ private final LogConfigManager logConfigManager;
+
+ private final String serviceClass;
+
+ private int useCount;
+
+ private Object service;
+
+ public ConfigurationServiceFactory(final LogConfigManager logConfigManager,
+ final String serviceClass) {
+ this.logConfigManager = logConfigManager;
+ this.serviceClass = serviceClass;
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ if (service == null) {
+ useCount = 1;
+ service = createInstance();
+ } else {
+ useCount++;
+ }
+ return service;
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration,
+ Object service) {
+ useCount--;
+ if (useCount <= 0) {
+ service = null;
+ }
+ }
+
+ private Object createInstance() {
+ try {
+ Class<?> type = getClass().getClassLoader().loadClass(serviceClass);
+ Object instance = type.newInstance();
+ if (instance instanceof LogConfigurator) {
+ ((LogConfigurator) instance).setLogConfigManager(logConfigManager);
+ }
+ return instance;
+ } catch (Throwable t) {
+ throw new RuntimeException("Failed to create " + serviceClass
+ + " instance", t);
+ }
+ }
+}
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/ConfigurationServiceFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java?rev=1043855&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java (added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java Thu Dec 9 08:12:02 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.config;
+
+import java.util.Dictionary;
+
+import org.osgi.service.cm.ManagedService;
+
+class GlobalConfigurator extends LogConfigurator implements ManagedService {
+
+ @SuppressWarnings("unchecked")
+ public void updated(Dictionary properties)
+ throws org.osgi.service.cm.ConfigurationException { // unchecked
+ try {
+ getLogConfigManager().updateGlobalConfiguration(properties);
+ } catch (ConfigurationException ce) {
+ throw new org.osgi.service.cm.ConfigurationException(
+ ce.getProperty(), ce.getReason(), ce);
+ }
+ }
+
+}
\ No newline at end of file
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/GlobalConfigurator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java?rev=1043855&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java (added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java Thu Dec 9 08:12:02 2010
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.config;
+
+import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+
+public class LogConfigurator {
+
+ private LogConfigManager logConfigManager;
+
+ void setLogConfigManager(final LogConfigManager logConfigManager) {
+ this.logConfigManager = logConfigManager;
+ }
+
+ LogConfigManager getLogConfigManager() {
+ return logConfigManager;
+ }
+
+}
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogConfigurator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java?rev=1043855&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java (added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java Thu Dec 9 08:12:02 2010
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.config;
+
+import java.util.Dictionary;
+
+import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+class LogWriterManagedServiceFactory extends LogConfigurator implements
+ ManagedServiceFactory {
+
+ public String getName() {
+ return "LogWriter configurator";
+ }
+
+ @SuppressWarnings("unchecked")
+ public void updated(String pid, Dictionary configuration)
+ throws org.osgi.service.cm.ConfigurationException {
+ try {
+ getLogConfigManager().updateLogWriter(pid, configuration);
+ } catch (ConfigurationException ce) {
+ throw new org.osgi.service.cm.ConfigurationException(
+ ce.getProperty(), ce.getReason(), ce);
+ }
+
+ }
+
+ public void deleted(String pid) {
+ try {
+ getLogConfigManager().updateLogWriter(pid, null);
+ } catch (ConfigurationException ce) {
+ // not expected
+ LogConfigManager.internalFailure(
+ "Unexpected Configuration Problem", ce);
+ }
+ }
+}
\ No newline at end of file
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LogWriterManagedServiceFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java?rev=1043855&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java (added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java Thu Dec 9 08:12:02 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.config;
+
+import java.util.Dictionary;
+
+import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+class LoggerManagedServiceFactory extends LogConfigurator implements
+ ManagedServiceFactory {
+
+ public String getName() {
+ return "Logger configurator";
+ }
+
+ @SuppressWarnings("unchecked")
+ public void updated(String pid, Dictionary configuration)
+ throws org.osgi.service.cm.ConfigurationException {
+ try {
+ getLogConfigManager().updateLoggerConfiguration(pid, configuration);
+ } catch (ConfigurationException ce) {
+ throw new org.osgi.service.cm.ConfigurationException(
+ ce.getProperty(), ce.getReason(), ce);
+ }
+ }
+
+ public void deleted(String pid) {
+ try {
+ getLogConfigManager().updateLoggerConfiguration(pid, null);
+ } catch (ConfigurationException ce) {
+ // not expected
+ LogConfigManager.internalFailure(
+ "Unexpected Configuration Problem", ce);
+ }
+ }
+}
\ No newline at end of file
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/config/LoggerManagedServiceFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/LogConfigManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/LogConfigManager.java?rev=1043855&r1=1043854&r2=1043855&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/LogConfigManager.java (original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/LogConfigManager.java Thu Dec 9 08:12:02 2010
@@ -30,7 +30,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.sling.commons.log.internal.LogManager;
-import org.osgi.service.cm.ConfigurationException;
+import org.apache.sling.commons.log.internal.config.ConfigurationException;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
@@ -71,6 +71,9 @@ public class LogConfigManager implements
// the root folder to make relative writer paths absolute
private File rootDir;
+ // global default configuration (from BundleContext properties)
+ private Dictionary<String, String> defaultConfiguration;
+
/**
* Returns the single instance of this log configuration instance.
*/
@@ -130,6 +133,21 @@ public class LogConfigManager implements
}
/**
+ * Sets and applies the default configuration used by the
+ * {@link #updateGlobalConfiguration(Dictionary)} method if no configuration
+ * is supplied.
+ */
+ public void setDefaultConfiguration(
+ Dictionary<String, String> defaultConfiguration) {
+ this.defaultConfiguration = defaultConfiguration;
+ try {
+ updateGlobalConfiguration(defaultConfiguration);
+ } catch (ConfigurationException ce) {
+ internalFailure(ce.getMessage(), ce);
+ }
+ }
+
+ /**
* Shuts this configuration manager down by dropping all references to
* existing configurations, dropping all stored loggers and closing all log
* writers.
@@ -208,6 +226,23 @@ public class LogConfigManager implements
// ---------- Configuration support
+ public void updateGlobalConfiguration(
+ Dictionary<String, String> configuration)
+ throws ConfigurationException {
+ // fallback to start default settings when the config is deleted
+ if (configuration == null) {
+ configuration = defaultConfiguration;
+ }
+
+ // set the logger name to a special value to indicate the global
+ // (ROOT) logger setting (SLING-529)
+ configuration.put(LogManager.LOG_LOGGERS, LogConfigManager.ROOT);
+
+ // update the default log writer and logger configuration
+ updateLogWriter(LogManager.PID, configuration);
+ updateLoggerConfiguration(LogManager.PID, configuration);
+ }
+
/**
* Updates or removes the log writer configuration identified by the
* <code>pid</code>. In case of log writer removal, any logger