[logback-dev] svn commit: r1945 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic logback-classic/src/main/java/ch/qos/logback/classic/jmx logback-classic/src/main/java/ch/qos/logback/classic/joran/action logback-classic/src/main/java/ch/qos/logback/classic/net logback-classic/src/main/java/ch/qos/logback/classic/selector logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet logback-classic/src/main/java/ch/qos/logback/classic/spi logback-classic/src/main/java/ch/qos/logback/classic/util logback-classic/src/test/java/ch/qos/logback/classic logback-classic/src/test/java/ch/qos/logback/classic/jmx logback-classic/src/test/java/ch/qos/logback/classic/net logback-classic/src/test/java/ch/qos/logback/classic/spi logback-classic/src/test/java/ch/qos/logback/classic/util logback-classic/src/test/java/org/dummy logback-core/src/main/java/ch/qos/logback/core/status logback-core/src/main/java/ch/qos/logback/core/util logback-core/src/test/java/ch/qos/l ogback/core/testUtil logback-examples/src/main/java/chapter2 logback-examples/src/main/java/chapter3 logback-examples/src/main/java/chapter4 logback-examples/src/main/java/chapter4/mail logback-examples/src/main/java/chapter4/socket logback-examples/src/main/java/chapter5 logback-examples/src/main/java/chapter6 logback-examples/src/main/java/chapter7
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Tue Nov 4 20:23:14 CET 2008
Author: ceki
Date: Tue Nov 4 20:23:14 2008
New Revision: 1945
Added:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java
- copied, changed from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfiguratorMBean.java
- copied, changed from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/MBeanUtil.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextListener.java
- copied, changed from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusListenerAsList.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusUtil.java
Removed:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/XTurboFilterAttachable.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/TurboFilteringInLoggerTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/InitializationTest.java
logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/RandomUtil.java
logback/trunk/logback-examples/src/main/java/chapter2/MyAppWithConfigFile.java
logback/trunk/logback-examples/src/main/java/chapter3/MyApp3.java
logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java
logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java
logback/trunk/logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java
logback/trunk/logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java
logback/trunk/logback-examples/src/main/java/chapter5/GoMDC.java
logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java
logback/trunk/logback-examples/src/main/java/chapter6/FilterEvents.java
logback/trunk/logback-examples/src/main/java/chapter7/NumberCruncherServer.java
logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java
Log:
This commit is related to:
LBCLASSIC-61 (configurable ObjectName)
LBCLASSIC-24 (better error messages after reload)
LBCLASSIC-33 (JMX configurator unregisters itself)
- Refactoring of LoggerContext class so it has a cleaner lifecycle
- Major refactorization of c.q.l.c.jmx.Configurator (renamed as JMXConfigurator) in order
to fix the aforementioned bugs
More updates to follow
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java Tue Nov 4 20:23:14 2008
@@ -20,7 +20,7 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.Marker;
-import ch.qos.logback.classic.spi.ContextListener;
+import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.classic.spi.LoggerComparator;
import ch.qos.logback.classic.spi.LoggerContextRemoteView;
import ch.qos.logback.classic.spi.TurboFilterList;
@@ -50,7 +50,7 @@
final Logger root;
private int size;
private int noAppenderWarning = 0;
- final private List<ContextListener> contextListenerList = new ArrayList<ContextListener>();
+ final private List<LoggerContextListener> loggerContextListenerList = new ArrayList<LoggerContextListener>();
// We want loggerCache to be synchronized so Hashtable is a good choice. In
// practice, it performs a little faster than the map returned by
@@ -189,15 +189,24 @@
return loggerContextRemoteView;
}
- public void shutdownAndReset() {
+ public void reset() {
root.recursiveReset();
clearAllTurboFilters();
fireOnReset();
// TODO is it a good idea to reset the status listeners?
resetStatusListeners();
+ resetListeners();
+ }
+
+ /**
+ * @deprecated Please use reset() method instead
+ */
+
+ public void shutdownAndReset() {
+ reset();
}
- void resetStatusListeners() {
+ private void resetStatusListeners() {
StatusManager sm = getStatusManager();
for (StatusListener sl : sm.getCopyOfStatusListenerList()) {
sm.remove(sl);
@@ -207,7 +216,7 @@
public TurboFilterList getTurboFilterList() {
return turboFilterList;
}
-
+
public void addTurboFilter(TurboFilter newFilter) {
turboFilterList.add(newFilter);
}
@@ -246,26 +255,37 @@
format, new Object[] { param1, param2 }, t);
}
- public void addListener(ContextListener listener) {
- contextListenerList.add(listener);
+ // === start listeners ==============================================
+ public void addListener(LoggerContextListener listener) {
+ loggerContextListenerList.add(listener);
+ }
+
+ public void removeListener(LoggerContextListener listener) {
+ loggerContextListenerList.remove(listener);
}
- public void removeListener(ContextListener listener) {
- contextListenerList.remove(listener);
+ private void resetListeners() {
+ loggerContextListenerList.clear();
+ }
+
+ public List<LoggerContextListener> getCopyOfListenerList() {
+ return new ArrayList<LoggerContextListener>(loggerContextListenerList);
}
private void fireOnReset() {
- for (ContextListener listener : contextListenerList) {
+ for (LoggerContextListener listener : loggerContextListenerList) {
listener.onReset(this);
}
}
private void fireOnStart() {
- for (ContextListener listener : contextListenerList) {
+ for (LoggerContextListener listener : loggerContextListenerList) {
listener.onStart(this);
}
}
+ // === end listeners ==============================================
+
public boolean isStarted() {
return started;
}
@@ -276,6 +296,7 @@
}
public void stop() {
+ reset();
started = false;
}
Copied: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java (from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java)
==============================================================================
--- /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java Tue Nov 4 20:23:14 2008
@@ -9,69 +9,118 @@
*/
package ch.qos.logback.classic.jmx;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusListenerAsList;
+import ch.qos.logback.core.status.StatusManager;
+import ch.qos.logback.core.util.StatusPrinter;
/**
- * A class that provides access to logback components via
- * JMX.
+ * A class that provides access to logback components via JMX.
+ *
+ * <p>Since this class implements {@link JMXConfiguratorMBean} it has to be
+ * named as Configurator}.
*
- *
* @author Ceki Gülcü
* @author Sébastien Pennec
*
- * Contributor:
- * Sebastian Davids
- * See http://bugzilla.qos.ch/show_bug.cgi?id=35
+ * Contributor: Sebastian Davids See http://bugzilla.qos.ch/show_bug.cgi?id=35
*/
-public class Configurator extends ContextAwareBase implements
- ConfiguratorMBean {
+public class JMXConfigurator extends ContextAwareBase implements
+ JMXConfiguratorMBean, LoggerContextListener {
private static String EMPTY = "";
-
- public Configurator(LoggerContext loggerContext) {
+
+ final LoggerContext loggerContext;
+ final MBeanServer mbs;
+ final ObjectName objectName;
+
+ public JMXConfigurator(LoggerContext loggerContext, MBeanServer mbs,
+ ObjectName objectName) {
this.context = loggerContext;
+ this.loggerContext = loggerContext;
+ this.mbs = mbs;
+ this.objectName = objectName;
+ removePreviousInstanceAsListener();
+ loggerContext.addListener(this);
+ }
+
+ private void removePreviousInstanceAsListener() {
+ List<LoggerContextListener> lcll = loggerContext.getCopyOfListenerList();
+
+ for (LoggerContextListener lcl : lcll) {
+ if (lcl instanceof JMXConfigurator) {
+ JMXConfigurator jmxConfigurator = (JMXConfigurator) lcl;
+ if (objectName.equals(jmxConfigurator.objectName)) {
+ addInfo("Removing previous JMXConfigurator from the logger context listener list");
+ loggerContext.removeListener(lcl);
+ }
+ }
+ }
}
- public void reload() {
- LoggerContext lc = (LoggerContext) context;
- addInfo("Shutting down context: " + lc.getName());
- lc.shutdownAndReset();
- try {
- new ContextInitializer(lc).autoConfig();
- addInfo("Context: " + lc.getName() + " reloaded.");
- } catch(JoranException je) {
- addError("Reloading of context: " + lc.getName() + " failed.", je);
+ public void reloadDefaultConfiguration() throws JoranException {
+ ContextInitializer ci = new ContextInitializer(loggerContext);
+ URL url = ci.findURLOfDefaultConfigurationFile(true);
+ reloadByURL(url);
+ }
+
+ public void reloadByFileName(String fileName) throws JoranException,
+ FileNotFoundException {
+ File f = new File(fileName);
+ if (f.exists() && f.isFile()) {
+ URL url;
+ try {
+ url = f.toURI().toURL();
+ reloadByURL(url);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(
+ "Unexpected MalformedURLException occured. See nexted cause.", e);
+ }
+
+ } else {
+ String errMsg = "Could not find [" + fileName + "]";
+ addInfo(errMsg);
+ throw new FileNotFoundException(errMsg);
}
}
- public void reload(String fileName) throws JoranException {
- LoggerContext lc = (LoggerContext) context;
- addInfo("Shutting down context: " + lc.getName());
- lc.shutdownAndReset();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(fileName);
- addInfo("Context: " + lc.getName() + " reloaded.");
- }
+ public void reloadByURL(URL url) throws JoranException {
+ StatusListenerAsList statusListenerAsList = new StatusListenerAsList();
+ StatusManager sm = loggerContext.getStatusManager();
+ sm.add(statusListenerAsList);
- public void reload(URL url) throws JoranException {
- LoggerContext lc = (LoggerContext) context;
- addInfo("Shutting down context: " + lc.getName());
- lc.shutdownAndReset();
- new ContextInitializer(lc).configureByResource(url);
- addInfo("Context: " + lc.getName() + " reloaded.");
+ addInfo("Resetting context: " + loggerContext.getName());
+ loggerContext.reset();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(loggerContext);
+ configurator.doConfigure(url);
+ addInfo("Context: " + loggerContext.getName() + " reloaded.");
+ } finally {
+ StatusPrinter.print(statusListenerAsList.getStatusList());
+ }
}
public void setLoggerLevel(String loggerName, String levelStr) {
@@ -83,10 +132,10 @@
}
loggerName = loggerName.trim();
levelStr = levelStr.trim();
-
+
addInfo("Trying to set level " + levelStr + " to logger " + loggerName);
LoggerContext lc = (LoggerContext) context;
-
+
Logger logger = lc.getLogger(loggerName);
if ("null".equalsIgnoreCase(levelStr)) {
logger.setLevel(null);
@@ -102,9 +151,9 @@
if (loggerName == null) {
return EMPTY;
}
-
+
loggerName = loggerName.trim();
-
+
LoggerContext lc = (LoggerContext) context;
Logger logger = lc.exists(loggerName);
if (logger != null) {
@@ -118,9 +167,9 @@
if (loggerName == null) {
return EMPTY;
}
-
+
loggerName = loggerName.trim();
-
+
LoggerContext lc = (LoggerContext) context;
Logger logger = lc.exists(loggerName);
if (logger != null) {
@@ -131,23 +180,54 @@
}
public List<String> getLoggerList() {
- LoggerContext lc = (LoggerContext)context;
+ LoggerContext lc = (LoggerContext) context;
List<String> strList = new ArrayList<String>();
Iterator<Logger> it = lc.getLoggerList().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Logger log = it.next();
strList.add(log.getName());
}
return strList;
}
-
+
public List<String> getStatuses() {
List<String> list = new ArrayList<String>();
- Iterator<Status> it = context.getStatusManager().getCopyOfStatusList().iterator();
- while(it.hasNext()) {
+ Iterator<Status> it = context.getStatusManager().getCopyOfStatusList()
+ .iterator();
+ while (it.hasNext()) {
list.add(it.next().toString());
}
return list;
}
+ /**
+ * When the associated LoggerContext is reset, this configurator must be
+ * unregistered
+ */
+ public void onReset(LoggerContext context) {
+ if (mbs.isRegistered(objectName)) {
+ try {
+ addInfo("Unregistering mbean [" + objectName + "]");
+ mbs.unregisterMBean(objectName);
+ } catch (InstanceNotFoundException e) {
+ // this is theoretically impossible
+ addError("Unable to find a verifiably registered mbean [" + objectName
+ + "]", e);
+ } catch (MBeanRegistrationException e) {
+ addError("Failed to unregister [" + objectName + "]", e);
+ }
+ } else {
+ addInfo("mbean [" + objectName
+ + "] was not in the mbean registry. This is OK.");
+ }
+
+ }
+
+ public void onStart(LoggerContext context) {
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getName() + "(" + context.getName() + ")";
+ }
}
Copied: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfiguratorMBean.java (from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java)
==============================================================================
--- /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfiguratorMBean.java Tue Nov 4 20:23:14 2008
@@ -9,18 +9,19 @@
*/
package ch.qos.logback.classic.jmx;
+import java.io.FileNotFoundException;
import java.net.URL;
import java.util.List;
import ch.qos.logback.core.joran.spi.JoranException;
-public interface ConfiguratorMBean {
+public interface JMXConfiguratorMBean {
- public void reload();
+ public void reloadDefaultConfiguration() throws JoranException;
- public void reload(String fileName) throws JoranException;
+ public void reloadByFileName(String fileName) throws JoranException, FileNotFoundException;
- public void reload(URL url) throws JoranException;
+ public void reloadByURL(URL url) throws JoranException;
public void setLoggerLevel(String loggerName, String levelStr);
Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/MBeanUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/MBeanUtil.java Tue Nov 4 20:23:14 2008
@@ -0,0 +1,96 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.jmx;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.status.StatusUtil;
+
+public class MBeanUtil {
+
+ static final String DOMAIN = "ch.qos.logback.classic";
+
+ static public String getObjectNameFor(Context context, Class type) {
+ String objectNameAsStr = DOMAIN + ":Name=" + context.getName() + ",Type="
+ + type.getName();
+ return objectNameAsStr;
+ }
+
+ public static ObjectName string2ObjectName(Context context, Object caller,
+ String objectNameAsStr) {
+ String msg = "Failed to convert [" + objectNameAsStr + "] to ObjectName";
+
+ try {
+ return new ObjectName(objectNameAsStr);
+ } catch (MalformedObjectNameException e) {
+ StatusUtil.addError(context, caller, msg, e);
+ return null;
+ } catch (NullPointerException e) {
+ StatusUtil.addError(context, caller, msg, e);
+ return null;
+ }
+ }
+
+ public static JMXConfigurator register(LoggerContext loggerContext,
+ ObjectName objectName, Object caller) {
+ try {
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+ JMXConfigurator jmxConfigurator = new JMXConfigurator(loggerContext,
+ mbs, objectName);
+
+ if (mbs.isRegistered(objectName)) {
+ StatusUtil.addWarn(loggerContext, caller,
+ "Unregistering existing MBean named ["
+ + objectName.getCanonicalName() + "]");
+ mbs.unregisterMBean(objectName);
+ }
+ mbs.registerMBean(jmxConfigurator, objectName);
+ return jmxConfigurator;
+ } catch (Exception e) {
+ StatusUtil.addError(loggerContext, caller, "Failed to create mbean", e);
+ return null;
+ }
+ }
+
+
+
+
+
+
+ public static void unregister(LoggerContext loggerContext, MBeanServer mbs,
+ ObjectName objectName, Object caller) {
+ if (mbs.isRegistered(objectName)) {
+ try {
+ StatusUtil.addInfo(loggerContext, caller, "Unregistering mbean ["
+ + objectName + "]");
+ mbs.unregisterMBean(objectName);
+ } catch (InstanceNotFoundException e) {
+ // this is theoretically impossible
+ e.printStackTrace();
+ } catch (MBeanRegistrationException e) {
+ // this also is theoretically impossible
+ e.printStackTrace();
+ }
+ } else {
+ StatusUtil.addInfo(loggerContext, caller, "mbean [" + objectName
+ + "] does not seem to be registered");
+ }
+ }
+
+}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java Tue Nov 4 20:23:14 2008
@@ -1,51 +1,48 @@
package ch.qos.logback.classic.joran.action;
-import java.lang.management.ManagementFactory;
-
-import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.xml.sax.Attributes;
import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.jmx.Configurator;
-import ch.qos.logback.classic.jmx.ConfiguratorMBean;
+import ch.qos.logback.classic.jmx.JMXConfigurator;
+import ch.qos.logback.classic.jmx.MBeanUtil;
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ActionException;
import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.util.OptionHelper;
public class JMXConfiguratorAction extends Action {
- static final String DOMAIN = "ch.qos.logback.classic";
-
+ static String OBJECT_NAME_ATTRIBUTE_NAME = "objectName";
+
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes)
throws ActionException {
- register();
- }
+ addInfo("begin");
- @Override
- public void end(InterpretationContext ec, String name) throws ActionException {
+ String objectNameAsStr;
+ String objectNameAttributeVal = attributes
+ .getValue(OBJECT_NAME_ATTRIBUTE_NAME);
+ if (OptionHelper.isEmpty(objectNameAttributeVal)) {
+ objectNameAsStr = MBeanUtil.getObjectNameFor((LoggerContext) context,
+ JMXConfigurator.class);
+ } else {
+ objectNameAsStr = objectNameAttributeVal;
+ }
+
+ ObjectName objectName = MBeanUtil.string2ObjectName(context, this,
+ objectNameAsStr);
+
+ if (objectName == null) {
+ MBeanUtil.register((LoggerContext) context, objectName, this);
+ }
}
- public void register() {
- ConfiguratorMBean configuratorMBean = new Configurator((LoggerContext) context);
+ @Override
+ public void end(InterpretationContext ec, String name) throws ActionException {
- MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- try {
- ObjectName on = new ObjectName(DOMAIN + ":Name=" + context.getName()
- + ",Type=" + configuratorMBean.getClass().getName());
-
- // StandardMBean mbean = new StandardMBean(configuratorMBean,
- // ConfiguratorMBean.class);
- if (mbs.isRegistered(on)) {
- mbs.unregisterMBean(on);
- }
- mbs.registerMBean(configuratorMBean, on);
- } catch (Exception e) {
- addError("Failed to create mbean", e);
- }
}
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java Tue Nov 4 20:23:14 2008
@@ -160,7 +160,7 @@
static public void configureLC(LoggerContext lc, String configFile)
throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
- lc.shutdownAndReset();
+ lc.reset();
configurator.setContext(lc);
configurator.doConfigure(configFile);
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/ContextJNDISelector.java Tue Nov 4 20:23:14 2008
@@ -119,7 +119,7 @@
if (url != null) {
try {
JoranConfigurator configurator = new JoranConfigurator();
- context.shutdownAndReset();
+ context.reset();
configurator.setContext(context);
configurator.doConfigure(url);
} catch (JoranException e) {
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java Tue Nov 4 20:23:14 2008
@@ -43,7 +43,7 @@
if (context != null) {
Logger logger = context.getLogger(LoggerContext.ROOT_NAME);
logger.warn("Shutting down context " + loggerContextName);
- context.shutdownAndReset();
+ context.reset();
} else {
System.out.println("No context named " + loggerContextName + " was found.");
}
Copied: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextListener.java (from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java)
==============================================================================
--- /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggerContextListener.java Tue Nov 4 20:23:14 2008
@@ -1,8 +1,17 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.classic.spi;
import ch.qos.logback.classic.LoggerContext;
-public interface ContextListener {
+public interface LoggerContextListener {
public void onReset(LoggerContext context);
public void onStart(LoggerContext context);
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java Tue Nov 4 20:23:14 2008
@@ -33,8 +33,7 @@
this.loggerContext = loggerContext;
}
- public void configureByResource(URL url)
- throws JoranException {
+ public void configureByResource(URL url) throws JoranException {
if (url == null) {
throw new IllegalArgumentException("URL argument cannot be null");
}
@@ -43,7 +42,7 @@
configurator.doConfigure(url);
}
- private URL findConfigFileURLFromSystemProperties() {
+ private URL findConfigFileURLFromSystemProperties(boolean updateStatus) {
String logbackConfigFile = System.getProperty(CONFIG_FILE_PROPERTY, null);
if (logbackConfigFile != null) {
URL result = null;
@@ -66,24 +65,38 @@
}
}
} finally {
- statusOnResourceSearch(logbackConfigFile, result);
+ if (updateStatus) {
+ statusOnResourceSearch(logbackConfigFile, result);
+ }
}
}
return null;
}
- public void autoConfig() throws JoranException {
- StatusListenerConfigHelper.installIfAsked(loggerContext);
+ public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
+ URL url = findConfigFileURLFromSystemProperties(updateStatus);
+ if (url != null) {
+ return url;
+ }
- URL url = findConfigFileURLFromSystemProperties();
- if (url == null) {
- url = Loader.getResourceBySelfClassLoader(TEST_AUTOCONFIG_FILE);
+ url = Loader.getResourceBySelfClassLoader(TEST_AUTOCONFIG_FILE);
+ if (updateStatus) {
statusOnResourceSearch(TEST_AUTOCONFIG_FILE, url);
}
- if (url == null) {
- url = Loader.getResourceBySelfClassLoader(AUTOCONFIG_FILE);
+ if (url != null) {
+ return url;
+ }
+
+ url = Loader.getResourceBySelfClassLoader(AUTOCONFIG_FILE);
+ if (updateStatus) {
statusOnResourceSearch(AUTOCONFIG_FILE, url);
}
+ return url;
+ }
+
+ public void autoConfig() throws JoranException {
+ StatusListenerConfigHelper.installIfAsked(loggerContext);
+ URL url = findURLOfDefaultConfigurationFile(true);
if (url != null) {
configureByResource(url);
} else {
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java Tue Nov 4 20:23:14 2008
@@ -23,9 +23,9 @@
suite.addTest(ch.qos.logback.classic.util.PackageTest.suite());
suite.addTest(ch.qos.logback.classic.control.PackageTest.suite());
suite.addTest(ch.qos.logback.classic.joran.PackageTest.suite());
+ suite.addTest(ch.qos.logback.classic.jmx.PackageTest.suite());
suite.addTest(ch.qos.logback.classic.boolex.PackageTest.suite());
suite.addTest(ch.qos.logback.classic.selector.PackageTest.suite());
-
suite.addTest(ch.qos.logback.classic.html.PackageTest.suite());
suite.addTest(ch.qos.logback.classic.net.PackageTest.suite());
suite.addTest(ch.qos.logback.classic.pattern.PackageTest.suite());
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/TurboFilteringInLoggerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/TurboFilteringInLoggerTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/TurboFilteringInLoggerTest.java Tue Nov 4 20:23:14 2008
@@ -134,7 +134,7 @@
public void testLoggingContextShutdownAndReset() {
addYesFilter();
assertNotNull(context.getTurboFilterList().get(0));
- context.shutdownAndReset();
+ context.reset();
assertEquals(0, context.getTurboFilterList().size());
}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java Tue Nov 4 20:23:14 2008
@@ -0,0 +1,86 @@
+package ch.qos.logback.classic.jmx;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.management.ManagementFactory;
+import java.util.List;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggerContextListener;
+import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class JMXConfiguratorTest {
+
+ static MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ LoggerContext lc = new LoggerContext();
+ List<LoggerContextListener> listenerList;
+ int diff = RandomUtil.getPositiveInt();
+
+ @Before
+ public void setUp() throws Exception {
+ lc.setName("context-" + diff);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lc.reset();
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getName() + "(" + lc.getName() + ")";
+ }
+
+ @Test
+ public void contextListening() {
+ String objectNameAsStr = "ch.qos.logback.toto" + ":Name=" + lc.getName()
+ + ",Type=" + this.getClass().getName();
+ ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
+
+ MBeanUtil.register(lc, on, this);
+ listenerList = lc.getCopyOfListenerList();
+ assertEquals(1, listenerList.size());
+ lc.reset();
+ listenerList = lc.getCopyOfListenerList();
+ assertEquals(0, listenerList.size());
+
+ MBeanUtil.register(lc, on, this);
+ listenerList = lc.getCopyOfListenerList();
+ assertEquals(1, listenerList.size());
+
+ }
+
+ @Test
+ public void testRemovalOfPreviousIntanceFromTheContextListenerList() {
+ String objectNameAsStr = "ch.qos.logback.toto" + ":Name=" + lc.getName()
+ + ",Type=" + this.getClass().getName();
+
+ ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
+ JMXConfigurator jmxConfigurator0 = MBeanUtil.register(lc, on, this);
+
+ listenerList = lc.getCopyOfListenerList();
+ assertEquals(1, listenerList.size());
+ assertTrue(listenerList.contains(jmxConfigurator0));
+
+ JMXConfigurator jmxConfigurator1 = MBeanUtil.register(lc, on, this);
+ listenerList = lc.getCopyOfListenerList();
+ assertEquals(1, listenerList.size());
+ assertFalse("old configurator should be absent", listenerList.contains(jmxConfigurator0));
+ assertTrue("new configurator should be present", listenerList.contains(jmxConfigurator1));
+
+ StatusPrinter.print(lc);
+
+ }
+
+}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java Tue Nov 4 20:23:14 2008
@@ -0,0 +1,25 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.jmx;
+
+
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class PackageTest extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new JUnit4TestAdapter (JMXConfiguratorTest.class));
+ return suite;
+ }
+}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java Tue Nov 4 20:23:14 2008
@@ -11,7 +11,7 @@
public static void main(String[] args) {
Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicAppenderTestApp.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- lc.shutdownAndReset();
+ lc.reset();
JMSQueueAppender appender = new JMSQueueAppender();
appender.setContext(lc);
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java Tue Nov 4 20:23:14 2008
@@ -11,7 +11,7 @@
public static void main(String[] args) {
Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicAppenderTestApp.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- lc.shutdownAndReset();
+ lc.reset();
JMSTopicAppender appender = new JMSTopicAppender();
appender.setContext(lc);
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java Tue Nov 4 20:23:14 2008
@@ -141,7 +141,7 @@
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(TestConstants.JORAN_ONPUT_PREFIX
+ "/syslog_LBCLASSIC_50.xml");
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java Tue Nov 4 20:23:14 2008
@@ -2,7 +2,7 @@
import ch.qos.logback.classic.LoggerContext;
-public class BasicContextListener implements ContextListener {
+public class BasicContextListener implements LoggerContextListener {
boolean updated = false;
LoggerContext context;
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java Tue Nov 4 20:23:14 2008
@@ -16,7 +16,7 @@
}
public void testNotifyOnReset() {
- context.shutdownAndReset();
+ context.reset();
assertTrue(listener.updated);
assertEquals(listener.context, context);
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/InitializationTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/InitializationTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/InitializationTest.java Tue Nov 4 20:23:14 2008
@@ -46,7 +46,7 @@
public void tearDown() throws Exception {
System.clearProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
System.clearProperty(ContextInitializer.STATUS_LISTENER_CLASS);
- lc.shutdownAndReset();
+ lc.reset();
}
@Test
@@ -73,7 +73,7 @@
assertTrue(appender instanceof ConsoleAppender);
}
{
- lc.shutdownAndReset();
+ lc.reset();
Appender appender = root.getAppender("STDOUT");
assertNull(appender);
}
Modified: logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java (original)
+++ logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java Tue Nov 4 20:23:14 2008
@@ -23,7 +23,7 @@
@Before
public void fixture() {
lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- lc.shutdownAndReset();
+ lc.reset();
listAppender = new DummyLBAppender();
listAppender.setContext(lc);
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusListenerAsList.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusListenerAsList.java Tue Nov 4 20:23:14 2008
@@ -0,0 +1,34 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.status;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Collect all incoming events in a list.
+ *
+ * @author Ceki Gülcü
+ *
+ */
+public class StatusListenerAsList implements StatusListener {
+
+ List<Status> statusList = new ArrayList<Status>();
+
+ public void addStatusEvent(Status status) {
+ statusList.add(status);
+ }
+
+ public List<Status> getStatusList() {
+ return statusList;
+ }
+
+
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusUtil.java Tue Nov 4 20:23:14 2008
@@ -0,0 +1,38 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.status;
+
+import ch.qos.logback.core.Context;
+
+public class StatusUtil {
+
+ static public void addStatus(Context context, Status status) {
+ if (context == null) {
+ return;
+ }
+ StatusManager sm = context.getStatusManager();
+ if (sm != null) {
+ sm.add(status);
+ }
+ }
+
+ static public void addInfo(Context context, Object caller, String msg) {
+ addStatus(context, new InfoStatus(msg, caller));
+ }
+
+ static public void addWarn(Context context, Object caller, String msg) {
+ addStatus(context, new WarnStatus(msg, caller));
+ }
+
+ static public void addError(Context context, Object caller, String msg,
+ Throwable t) {
+ addStatus(context, new ErrorStatus(msg, caller, t));
+ }
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java Tue Nov 4 20:23:14 2008
@@ -14,14 +14,15 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.Layout;
+import ch.qos.logback.core.helpers.ThrowableToStringArray;
import ch.qos.logback.core.status.ErrorStatus;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
-import ch.qos.logback.core.helpers.ThrowableToStringArray;
public class StatusPrinter {
@@ -35,8 +36,8 @@
}
/**
- * Print the contents of the context statuses, but only if they
- * contain errors.
+ * Print the contents of the context statuses, but only if they contain
+ * errors.
*
* @param context
*/
@@ -78,18 +79,29 @@
public static void print(StatusManager sm) {
StringBuilder sb = new StringBuilder();
- buildStr(sb, sm);
+ buildStrFromStatusManager(sb, sm);
ps.println(sb.toString());
}
- public static void buildStr(StringBuilder sb, StatusManager sm) {
- Iterator it = sm.getCopyOfStatusList().iterator();
+ public static void print(List<Status> statusList) {
+ StringBuilder sb = new StringBuilder();
+ buildStrFromStatusList(sb, statusList);
+ ps.println(sb.toString());
+ }
+
+
+ private static void buildStrFromStatusList(StringBuilder sb, List<Status> statusList) {
+ Iterator it = statusList.iterator();
while (it.hasNext()) {
Status s = (Status) it.next();
buildStr(sb, "", s);
}
}
+ private static void buildStrFromStatusManager(StringBuilder sb, StatusManager sm) {
+ buildStrFromStatusList(sb, sm.getCopyOfStatusList());
+ }
+
private static void appendThrowable(StringBuilder sb, Throwable t) {
String[] stringRep = ThrowableToStringArray.convert(t);
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/RandomUtil.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/RandomUtil.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/RandomUtil.java Tue Nov 4 20:23:14 2008
@@ -21,4 +21,11 @@
return r + 1024;
}
+ public static int getPositiveInt() {
+ int r = random.nextInt();
+ if (r < 0) {
+ r = -r;
+ }
+ return r;
+ }
}
Modified: logback/trunk/logback-examples/src/main/java/chapter2/MyAppWithConfigFile.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter2/MyAppWithConfigFile.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter2/MyAppWithConfigFile.java Tue Nov 4 20:23:14 2008
@@ -26,7 +26,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
- lc.shutdownAndReset();
+ lc.reset();
configurator.setContext(lc);
configurator.doConfigure(args[0]);
} catch (JoranException je) {
Modified: logback/trunk/logback-examples/src/main/java/chapter3/MyApp3.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter3/MyApp3.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter3/MyApp3.java Tue Nov 4 20:23:14 2008
@@ -33,7 +33,7 @@
configurator.setContext(lc);
// the context was probably already configured by default configuration
// rules
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
je.printStackTrace();
Modified: logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java Tue Nov 4 20:23:14 2008
@@ -41,7 +41,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
je.printStackTrace();
Modified: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java Tue Nov 4 20:23:14 2008
@@ -25,7 +25,7 @@
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- lc.shutdownAndReset(); // we want to override the default-config.
+ lc.reset(); // we want to override the default-config.
WriterAppender<LoggingEvent> writerAppender = new WriterAppender<LoggingEvent>();
writerAppender.setContext(lc);
writerAppender.setLayout(new EchoLayout<LoggingEvent>());
Modified: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java Tue Nov 4 20:23:14 2008
@@ -26,7 +26,7 @@
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- lc.shutdownAndReset();//this is to cancel default-config.
+ lc.reset();//this is to cancel default-config.
WriterAppender<LoggingEvent> writerAppender = new WriterAppender<LoggingEvent>();
writerAppender.setContext(lc);
writerAppender.setLayout(new EchoLayout<LoggingEvent>());
@@ -42,7 +42,7 @@
logger.debug("Hello world.");
- lc.shutdownAndReset();
+ lc.reset();
StatusPrinter.print(lc);
}
Modified: logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java Tue Nov 4 20:23:14 2008
@@ -35,7 +35,7 @@
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
- lc.shutdownAndReset();
+ lc.reset();
configurator.setContext(lc);
configurator.doConfigure(configFile);
StatusPrinter.printIfErrorsOccured(lc);
Modified: logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java Tue Nov 4 20:23:14 2008
@@ -45,7 +45,7 @@
if (configFile.endsWith(".xml")) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
- lc.shutdownAndReset();
+ lc.reset();
configurator.setContext(lc);
configurator.doConfigure(configFile);
}
Modified: logback/trunk/logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java Tue Nov 4 20:23:14 2008
@@ -18,7 +18,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
StatusPrinter.print(lc);
Modified: logback/trunk/logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java Tue Nov 4 20:23:14 2008
@@ -17,7 +17,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
StatusPrinter.print(lc);
Modified: logback/trunk/logback-examples/src/main/java/chapter5/GoMDC.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/GoMDC.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/GoMDC.java Tue Nov 4 20:23:14 2008
@@ -19,7 +19,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure("mdcFilter.xml");
} catch (JoranException je) {
Modified: logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java Tue Nov 4 20:23:14 2008
@@ -17,7 +17,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
- lc.shutdownAndReset();
+ lc.reset();
configurator.setContext(lc);
configurator.doConfigure(args[0]);
} catch (JoranException je) {
Modified: logback/trunk/logback-examples/src/main/java/chapter6/FilterEvents.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter6/FilterEvents.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter6/FilterEvents.java Tue Nov 4 20:23:14 2008
@@ -24,7 +24,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
je.printStackTrace();
Modified: logback/trunk/logback-examples/src/main/java/chapter7/NumberCruncherServer.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter7/NumberCruncherServer.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter7/NumberCruncherServer.java Tue Nov 4 20:23:14 2008
@@ -134,7 +134,7 @@
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
je.printStackTrace();
Modified: logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java Tue Nov 4 20:23:14 2008
@@ -59,7 +59,7 @@
// Configure logback
LoggerContext loggerContext = (LoggerContext) LoggerFactory
.getILoggerFactory();
- loggerContext.shutdownAndReset();
+ loggerContext.reset();
PatternLayout layout = new PatternLayout();
layout.setContext(loggerContext);
layout.setPattern("%X{first} %X{last} - %m%n");
@@ -80,7 +80,7 @@
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
- lc.shutdownAndReset();
+ lc.reset();
URL url = Loader.getResourceBySelfClassLoader("chapter7/simpleMDC.xml");
configurator.doConfigure(url);
} catch (JoranException je) {
More information about the logback-dev
mailing list