[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-89-g4fa9166
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Thu Mar 18 13:50:36 CET 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 4fa9166747fccbaed7f35a5c877d0aaaf41168c5 (commit)
from 8e4097f3a23fc9ddc57846ad55e5c7100d2a4a63 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=4fa9166747fccbaed7f35a5c877d0aaaf41168c5
http://github.com/ceki/logback/commit/4fa9166747fccbaed7f35a5c877d0aaaf41168c5
commit 4fa9166747fccbaed7f35a5c877d0aaaf41168c5
Author: Ceki Gulcu <ceki at qos.ch>
Date: Thu Mar 18 13:48:52 2010 +0100
- removed references to org.slf4j.impl package from ch.qos.logback.classic
as requested in LBCLASSIC-184
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java b/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
index fdfc23b..981e2cd 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
@@ -21,10 +21,10 @@ import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
-import org.slf4j.impl.StaticLoggerBinder;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.selector.ContextSelector;
+import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.classic.util.JNDIUtil;
public class ContextDetachingSCL implements ServletContextListener {
@@ -41,7 +41,7 @@ public class ContextDetachingSCL implements ServletContextListener {
if (loggerContextName != null) {
System.out.println("About to detach context named " + loggerContextName);
- ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
+ ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
LoggerContext context = selector.detachLoggerContext(loggerContextName);
if (context != null) {
Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME);
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java b/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java
index 3b18bd1..5f80a7c 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java
@@ -23,11 +23,11 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.slf4j.LoggerFactory;
-import org.slf4j.impl.StaticLoggerBinder;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.selector.ContextJNDISelector;
import ch.qos.logback.classic.selector.ContextSelector;
+import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
/**
* A servlet filter that puts the environment dependent LoggerContext in a
@@ -58,7 +58,7 @@ public class LoggerContextFilter implements Filter {
FilterChain chain) throws IOException, ServletException {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
+ ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
ContextJNDISelector sel = null;
if (selector instanceof ContextJNDISelector) {
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/sift/JNDIBasedContextDiscriminator.java b/logback-classic/src/main/java/ch/qos/logback/classic/sift/JNDIBasedContextDiscriminator.java
index 499c2f6..dac6a24 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/sift/JNDIBasedContextDiscriminator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/sift/JNDIBasedContextDiscriminator.java
@@ -13,11 +13,10 @@
*/
package ch.qos.logback.classic.sift;
-import org.slf4j.impl.StaticLoggerBinder;
-
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.selector.ContextSelector;
import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.core.sift.Discriminator;
import ch.qos.logback.core.spi.ContextAwareBase;
@@ -45,7 +44,7 @@ public class JNDIBasedContextDiscriminator extends ContextAwareBase implements
* Return the name of the current context name as found in the logging event.
*/
public String getDiscriminatingValue(ILoggingEvent event) {
- ContextSelector selector = StaticLoggerBinder.getSingleton()
+ ContextSelector selector = ContextSelectorStaticBinder.getSingleton()
.getContextSelector();
if (selector == null) {
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index dad1588..867c9d2 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@ -19,11 +19,11 @@ import java.util.Map;
import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.helpers.MessageFormatter;
-import org.slf4j.impl.LogbackMDCAdapter;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.util.LogbackMDCAdapter;
/**
* The internal representation of logging events. When an affirmative decision
diff --git a/logback-classic/src/main/java/org/slf4j/impl/CopyOnInheritThreadLocal.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/CopyOnInheritThreadLocal.java
similarity index 96%
rename from logback-classic/src/main/java/org/slf4j/impl/CopyOnInheritThreadLocal.java
rename to logback-classic/src/main/java/ch/qos/logback/classic/util/CopyOnInheritThreadLocal.java
index 5b2a519..116821a 100644
--- a/logback-classic/src/main/java/org/slf4j/impl/CopyOnInheritThreadLocal.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/CopyOnInheritThreadLocal.java
@@ -11,7 +11,7 @@
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
-package org.slf4j.impl;
+package ch.qos.logback.classic.util;
import java.util.HashMap;
diff --git a/logback-classic/src/main/java/org/slf4j/impl/LogbackMDCAdapter.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
similarity index 98%
rename from logback-classic/src/main/java/org/slf4j/impl/LogbackMDCAdapter.java
rename to logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
index 93b4c1e..9af2532 100644
--- a/logback-classic/src/main/java/org/slf4j/impl/LogbackMDCAdapter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
@@ -11,7 +11,7 @@
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
-package org.slf4j.impl;
+package ch.qos.logback.classic.util;
import java.util.HashMap;
import java.util.Map;
@@ -19,6 +19,7 @@ import java.util.Set;
import org.slf4j.spi.MDCAdapter;
+
/**
* A <em>Mapped Diagnostic Context</em>, or MDC in short, is an instrument
* for distinguishing interleaved log output from different sources. Log output
@@ -39,7 +40,7 @@ public class LogbackMDCAdapter implements MDCAdapter {
final CopyOnInheritThreadLocal copyOnInheritThreadLocal = new CopyOnInheritThreadLocal();
- LogbackMDCAdapter() {
+ public LogbackMDCAdapter() {
}
/**
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java
deleted file mode 100644
index 56004be..0000000
--- a/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- * or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.classic.util;
-
-import org.slf4j.LoggerFactory;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.core.util.StatusPrinter;
-
-public class LoggerStatusPrinter {
-
- public static void printStatusInDefaultContext() {
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- StatusPrinter.print(lc);
- }
-
-}
diff --git a/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java b/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
index f8c2ea8..c0ef94f 100644
--- a/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
+++ b/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
@@ -13,24 +13,16 @@
*/
package org.slf4j.impl;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.Util;
import org.slf4j.spi.LoggerFactoryBinder;
-import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.selector.ContextJNDISelector;
-import ch.qos.logback.classic.selector.ContextSelector;
-import ch.qos.logback.classic.selector.DefaultContextSelector;
import ch.qos.logback.classic.util.ContextInitializer;
+import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.util.Loader;
-import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.StatusPrinter;
/**
@@ -38,7 +30,7 @@ import ch.qos.logback.core.util.StatusPrinter;
* The binding of {@link LoggerFactory} class with an actual instance of
* {@link ILoggerFactory} is performed using information returned by this class.
*
- * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a>
+ * @author <a href="http://www.qos.ch/shop/products/log4jManual">Ceki Gülcü</a>
*/
public class StaticLoggerBinder implements LoggerFactoryBinder {
@@ -47,7 +39,7 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
* against. The value of this field is usually modified with each release.
*/
// to avoid constant folding by the compiler, this field must *not* be final
- public static String REQUESTED_API_VERSION = "1.5.8"; // !final
+ public static String REQUESTED_API_VERSION = "1.5.11"; // !final
final static String NULL_CS_URL = CoreConstants.CODES_URL + "#null_CS";
@@ -56,14 +48,16 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
*/
private static StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+ private static Object KEY = new Object();
+
static {
SINGLETON.init();
}
private boolean initialized = false;
private LoggerContext defaultLoggerContext = new LoggerContext();
- private ContextSelector contextSelector;
-
+ private final ContextSelectorStaticBinder contextSelectorBinder = ContextSelectorStaticBinder.getSingleton();
+
private StaticLoggerBinder() {
defaultLoggerContext.setName(CoreConstants.DEFAULT_CONTEXT_NAME);
}
@@ -92,19 +86,7 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
je);
}
StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
-
- // See if a special context selector is needed
- String contextSelectorStr = OptionHelper
- .getSystemProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR);
- if (contextSelectorStr == null) {
- contextSelector = new DefaultContextSelector(defaultLoggerContext);
- } else if (contextSelectorStr.equals("JNDI")) {
- // if jndi is specified, let's use the appropriate class
- contextSelector = new ContextJNDISelector(defaultLoggerContext);
- } else {
- contextSelector = dynamicalContextSelector(defaultLoggerContext,
- contextSelectorStr);
- }
+ contextSelectorBinder.init(defaultLoggerContext, KEY);
initialized = true;
} catch (Throwable t) {
// we should never get here
@@ -113,55 +95,23 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
}
}
- /**
- * Intantiate the context selector class designated by the user. The selector
- * must have a constructor taking a LoggerContext instance as an argument.
- *
- * @param defaultLoggerContext
- * @param contextSelectorStr
- * @return an instance of the designated context selector class
- * @throws ClassNotFoundException
- * @throws SecurityException
- * @throws NoSuchMethodException
- * @throws IllegalArgumentException
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- */
- static ContextSelector dynamicalContextSelector(
- LoggerContext defaultLoggerContext, String contextSelectorStr)
- throws ClassNotFoundException, SecurityException, NoSuchMethodException,
- IllegalArgumentException, InstantiationException, IllegalAccessException,
- InvocationTargetException {
- Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr);
- Constructor cons = contextSelectorClass
- .getConstructor(new Class[] { LoggerContext.class });
- return (ContextSelector) cons.newInstance(defaultLoggerContext);
- }
+
public ILoggerFactory getLoggerFactory() {
if (!initialized) {
return defaultLoggerContext;
}
- if (contextSelector == null) {
+ if (contextSelectorBinder.getContextSelector() == null) {
throw new IllegalStateException(
"contextSelector cannot be null. See also " + NULL_CS_URL);
}
- return contextSelector.getLoggerContext();
+ return contextSelectorBinder.getContextSelector().getLoggerContext();
}
public String getLoggerFactoryClassStr() {
- return contextSelector.getClass().getName();
- }
-
- /**
- * Return the {@link ContextSelector} instance in use.
- *
- * @return the ContextSelector instance in use
- */
- public ContextSelector getContextSelector() {
- return contextSelector;
+ return contextSelectorBinder.getContextSelector().getClass().getName();
}
+
}
diff --git a/logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java b/logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java
index c24fca8..70c13b0 100644
--- a/logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java
+++ b/logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java
@@ -15,6 +15,8 @@ package org.slf4j.impl;
import org.slf4j.spi.MDCAdapter;
+import ch.qos.logback.classic.util.LogbackMDCAdapter;
+
/**
* This implementation is bound to {@link LogbackMDCAdapter}.
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
index 260082c..192f580 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
@@ -19,10 +19,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
-import org.slf4j.impl.StaticLoggerBinder;
import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.selector.servlet.ContextDetachingSCL;
+import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.classic.util.MockInitialContext;
import ch.qos.logback.classic.util.MockInitialContextFactory;
@@ -30,14 +30,14 @@ public class ContextDetachingSCLTest {
static String INITIAL_CONTEXT_KEY = "java.naming.factory.initial";
- ContextDetachingSCL listener;
+ ContextDetachingSCL cobtextDetachingSCL;
@Before
public void setUp() throws Exception {
System.setProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR, "JNDI");
//LoggerFactory.setup();
- listener = new ContextDetachingSCL();
+ cobtextDetachingSCL = new ContextDetachingSCL();
MockInitialContextFactory.initialize();
MockInitialContext mic = MockInitialContextFactory.getContext();
@@ -58,8 +58,8 @@ public class ContextDetachingSCLTest {
@Test
public void testDetach() {
- ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.getSingleton().getContextSelector();
- listener.contextDestroyed(null);
+ ContextJNDISelector selector = (ContextJNDISelector) ContextSelectorStaticBinder.getSingleton().getContextSelector();
+ cobtextDetachingSCL.contextDestroyed(null);
assertEquals(0, selector.getCount());
}
@@ -68,12 +68,12 @@ public class ContextDetachingSCLTest {
public void testDetachWithMissingContext() {
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, "tata");
- ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.getSingleton().getContextSelector();
+ ContextJNDISelector selector = (ContextJNDISelector) ContextSelectorStaticBinder.getSingleton().getContextSelector();
assertEquals("tata", selector.getLoggerContext().getName());
mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, "titi");
assertEquals("titi", selector.getLoggerContext().getName());
- listener.contextDestroyed(null);
+ cobtextDetachingSCL.contextDestroyed(null);
assertEquals(2, selector.getCount());
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java
index 8e41eb1..59cdafe 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java
@@ -19,10 +19,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
-import org.slf4j.impl.StaticLoggerBinder;
import org.slf4j.impl.StaticLoggerBinderFriend;
import ch.qos.logback.classic.ClassicConstants;
+import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.classic.util.MockInitialContext;
import ch.qos.logback.classic.util.MockInitialContextFactory;
import ch.qos.logback.core.Context;
@@ -55,7 +55,7 @@ public class ContextJNDISelectorTest {
@Test
public void testGetExistingContext() {
- ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
+ ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
Context context = selector.getLoggerContext();
assertEquals("toto", context.getName());
}
@@ -67,7 +67,7 @@ public class ContextJNDISelectorTest {
LoggerFactory.getLogger(ContextDetachingSCLTest.class);
- ContextJNDISelector selector = (ContextJNDISelector)StaticLoggerBinder.getSingleton().getContextSelector();
+ ContextJNDISelector selector = (ContextJNDISelector)ContextSelectorStaticBinder.getSingleton().getContextSelector();
Context context = selector.getLoggerContext();
assertEquals("tata", context.getName());
System.out.println(selector.getContextNames());
@@ -79,7 +79,7 @@ public class ContextJNDISelectorTest {
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, null);
- ContextJNDISelector selector = (ContextJNDISelector)StaticLoggerBinder.getSingleton().getContextSelector();
+ ContextJNDISelector selector = (ContextJNDISelector)ContextSelectorStaticBinder.getSingleton().getContextSelector();
Context context = selector.getLoggerContext();
assertEquals("default", context.getName());
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextSelectorStaticBinder.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextSelectorStaticBinder.java
new file mode 100644
index 0000000..a2d9a02
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextSelectorStaticBinder.java
@@ -0,0 +1,107 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2010, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under either
+ * the terms of the Eclipse Public License v1.0 as published by the Eclipse
+ * Foundation
+ *
+ * or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ */
+package ch.qos.logback.classic.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import ch.qos.logback.classic.ClassicConstants;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.selector.ContextJNDISelector;
+import ch.qos.logback.classic.selector.ContextSelector;
+import ch.qos.logback.classic.selector.DefaultContextSelector;
+import ch.qos.logback.core.util.Loader;
+import ch.qos.logback.core.util.OptionHelper;
+
+/**
+ * Holds the context selector for use in the current environment.
+ *
+ * @author Ceki Gülcü
+ * @since 0.9.19
+ */
+public class ContextSelectorStaticBinder {
+
+ static ContextSelectorStaticBinder singleton = new ContextSelectorStaticBinder();
+
+ ContextSelector contextSelector;
+ Object key;
+
+ public static ContextSelectorStaticBinder getSingleton() {
+ return singleton;
+ }
+
+ /**
+ * FOR INTERNAL USE. This method is intended for use by StaticLoggerBinder.
+ *
+ * @param defaultLoggerContext
+ * @throws ClassNotFoundException
+ * @throws NoSuchMethodException
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ public void init(LoggerContext defaultLoggerContext, Object key) throws ClassNotFoundException,
+ NoSuchMethodException, InstantiationException, IllegalAccessException,
+ InvocationTargetException {
+ if(this.key == null) {
+ this.key = key;
+ } else if (this.key != key) {
+ throw new IllegalAccessException("Only certain classes can access this method.");
+ }
+
+
+ String contextSelectorStr = OptionHelper
+ .getSystemProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR);
+ if (contextSelectorStr == null) {
+ contextSelector = new DefaultContextSelector(defaultLoggerContext);
+ } else if (contextSelectorStr.equals("JNDI")) {
+ // if jndi is specified, let's use the appropriate class
+ contextSelector = new ContextJNDISelector(defaultLoggerContext);
+ } else {
+ contextSelector = dynamicalContextSelector(defaultLoggerContext,
+ contextSelectorStr);
+ }
+ }
+
+ /**
+ * Intantiate the context selector class designated by the user. The selector
+ * must have a constructor taking a LoggerContext instance as an argument.
+ *
+ * @param defaultLoggerContext
+ * @param contextSelectorStr
+ * @return an instance of the designated context selector class
+ * @throws ClassNotFoundException
+ * @throws SecurityException
+ * @throws NoSuchMethodException
+ * @throws IllegalArgumentException
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ static ContextSelector dynamicalContextSelector(
+ LoggerContext defaultLoggerContext, String contextSelectorStr)
+ throws ClassNotFoundException, SecurityException, NoSuchMethodException,
+ IllegalArgumentException, InstantiationException, IllegalAccessException,
+ InvocationTargetException {
+ Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr);
+ Constructor cons = contextSelectorClass
+ .getConstructor(new Class[] { LoggerContext.class });
+ return (ContextSelector) cons.newInstance(defaultLoggerContext);
+ }
+
+ public ContextSelector getContextSelector() {
+ return contextSelector;
+ }
+
+}
diff --git a/logback-classic/src/test/java/org/slf4j/impl/LogbackMDCAdapterTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
similarity index 95%
rename from logback-classic/src/test/java/org/slf4j/impl/LogbackMDCAdapterTest.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
index 8546cca..4c8cf51 100644
--- a/logback-classic/src/test/java/org/slf4j/impl/LogbackMDCAdapterTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
@@ -11,7 +11,7 @@
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
-package org.slf4j.impl;
+package ch.qos.logback.classic.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -24,6 +24,9 @@ import java.util.Random;
import org.junit.Test;
import org.slf4j.MDC;
+import ch.qos.logback.classic.util.CopyOnInheritThreadLocal;
+import ch.qos.logback.classic.util.LogbackMDCAdapter;
+
public class LogbackMDCAdapterTest {
final static String A_SUFFIX = "A_SUFFIX";
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java
index 4b63ded..0256b5a 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java
@@ -19,7 +19,7 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
- at SuiteClasses({InitializationTest.class, LevelToSyslogSeverityTest.class} )
+ at SuiteClasses({InitializationTest.class, LogbackMDCAdapterTest.class, LevelToSyslogSeverityTest.class} )
public class PackageTest {
}
\ No newline at end of file
diff --git a/logback-examples/src/main/java/chapters/architecture/HelloWorld2.java b/logback-examples/src/main/java/chapters/architecture/HelloWorld2.java
deleted file mode 100644
index 3480847..0000000
--- a/logback-examples/src/main/java/chapters/architecture/HelloWorld2.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- * or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package chapters.architecture;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import ch.qos.logback.classic.util.LoggerStatusPrinter;
-
-public class HelloWorld2 {
-
- public static void main(String[] args) {
- Logger logger = LoggerFactory.getLogger("manual.architecture.HelloWorld2");
- logger.debug("Hello world.");
- LoggerStatusPrinter.printStatusInDefaultContext();
- }
-}
-----------------------------------------------------------------------
Summary of changes:
.../selector/servlet/ContextDetachingSCL.java | 4 +-
.../selector/servlet/LoggerContextFilter.java | 4 +-
.../sift/JNDIBasedContextDiscriminator.java | 5 +-
.../ch/qos/logback/classic/spi/LoggingEvent.java | 2 +-
.../classic/util}/CopyOnInheritThreadLocal.java | 2 +-
.../logback/classic/util}/LogbackMDCAdapter.java | 5 +-
.../logback/classic/util/LoggerStatusPrinter.java | 28 -----
.../java/org/slf4j/impl/StaticLoggerBinder.java | 76 +++------------
.../main/java/org/slf4j/impl/StaticMDCBinder.java | 2 +
.../classic/selector/ContextDetachingSCLTest.java | 14 ++--
.../classic/selector/ContextJNDISelectorTest.java | 8 +-
.../classic/util/ContextSelectorStaticBinder.java | 107 ++++++++++++++++++++
.../classic/util}/LogbackMDCAdapterTest.java | 5 +-
.../ch/qos/logback/classic/util/PackageTest.java | 2 +-
.../java/chapters/architecture/HelloWorld2.java | 28 -----
15 files changed, 149 insertions(+), 143 deletions(-)
rename logback-classic/src/main/java/{org/slf4j/impl => ch/qos/logback/classic/util}/CopyOnInheritThreadLocal.java (96%)
rename logback-classic/src/main/java/{org/slf4j/impl => ch/qos/logback/classic/util}/LogbackMDCAdapter.java (98%)
delete mode 100644 logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java
create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/util/ContextSelectorStaticBinder.java
rename logback-classic/src/test/java/{org/slf4j/impl => ch/qos/logback/classic/util}/LogbackMDCAdapterTest.java (95%)
delete mode 100644 logback-examples/src/main/java/chapters/architecture/HelloWorld2.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list