[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.24-27-ge519c39

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 e519c39a35da84d83a8c5121490551473d6f92fa (commit) from 55270dc26b29a3c36ae62661bc33f4291ae71b6d (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=e519c39a35da84d83a8c51214... http://github.com/ceki/logback/commit/e519c39a35da84d83a8c5121490551473d6f92... commit e519c39a35da84d83a8c5121490551473d6f92fa Author: Ceki Gulcu <ceki@qos.ch> Date: Wed Oct 13 18:47:13 2010 +0200 - work on LevelChangePropagator completed. diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java index 765498a..eecff0c 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java @@ -13,15 +13,7 @@ */ package ch.qos.logback.classic.joran; -import ch.qos.logback.classic.joran.action.ConfigurationAction; -import ch.qos.logback.classic.joran.action.ConsolePluginAction; -import ch.qos.logback.classic.joran.action.ContextNameAction; -import ch.qos.logback.classic.joran.action.EvaluatorAction; -import ch.qos.logback.classic.joran.action.InsertFromJNDIAction; -import ch.qos.logback.classic.joran.action.JMXConfiguratorAction; -import ch.qos.logback.classic.joran.action.LevelAction; -import ch.qos.logback.classic.joran.action.LoggerAction; -import ch.qos.logback.classic.joran.action.RootLoggerAction; +import ch.qos.logback.classic.joran.action.*; import ch.qos.logback.classic.sift.SiftAction; import ch.qos.logback.classic.spi.PlatformInfo; import ch.qos.logback.classic.util.DefaultNestedComponentRules; @@ -55,6 +47,8 @@ public class JoranConfigurator extends JoranConfiguratorBase { rs.addRule(new Pattern("configuration/contextName"), new ContextNameAction()); + rs.addRule(new Pattern("configuration/contextListener"), + new LoggerContextListenerAction()); rs.addRule(new Pattern("configuration/insertFromJNDI"), new InsertFromJNDIAction()); rs.addRule(new Pattern("configuration/evaluator"), new EvaluatorAction()); diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java index 5f77002..a50fb49 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java @@ -60,7 +60,7 @@ public class JMXConfiguratorAction extends Action { ObjectName objectName = MBeanUtil.string2ObjectName(context, this, objectNameAsStr); if (objectName == null) { - addError("Failed to for ObjectName for ["+objectNameAsStr+"]"); + addError("Failed construct ObjectName for ["+objectNameAsStr+"]"); return; } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerContextListenerAction.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerContextListenerAction.java index fe6890e..ff1e65b 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerContextListenerAction.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerContextListenerAction.java @@ -1,6 +1,6 @@ /** * Logback: the reliable, generic, fast and flexible logging framework. - * Copyright (C) 1999-2009, QOS.ch. All rights reserved. + * 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 @@ -20,6 +20,7 @@ import javax.management.ObjectName; import ch.qos.logback.classic.spi.LoggerContextListener; import ch.qos.logback.core.boolex.EventEvaluator; +import ch.qos.logback.core.spi.ContextAware; import ch.qos.logback.core.spi.LifeCycle; import org.xml.sax.Attributes; @@ -53,6 +54,10 @@ public class LoggerContextListenerAction extends Action { lcl = (LoggerContextListener) OptionHelper.instantiateByClassName( className, LoggerContextListener.class, context); + if(lcl instanceof ContextAware) { + ((ContextAware) lcl).setContext(context); + } + ec.pushObject(lcl); addInfo("Adding LoggerContextListener of type [" + className + "] to the object stack"); @@ -73,6 +78,11 @@ public class LoggerContextListenerAction extends Action { if (o != lcl) { addWarn("The object on the top the of the stack is not the LoggerContextListener pushed earlier."); } else { + if (lcl instanceof LifeCycle) { + ((LifeCycle) lcl).start(); + addInfo("Starting LoggerContextListener"); + } + ((LoggerContext) context).addListener(lcl); ec.popObject(); } } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java index 047269b..34f3045 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java @@ -40,7 +40,6 @@ public class RootLoggerAction extends Action { addInfo("Setting level of ROOT logger to " + level); root.setLevel(level); } - ec.pushObject(root); } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/jul/JULHelper.java b/logback-classic/src/main/java/ch/qos/logback/classic/jul/JULHelper.java new file mode 100644 index 0000000..05d52bb --- /dev/null +++ b/logback-classic/src/main/java/ch/qos/logback/classic/jul/JULHelper.java @@ -0,0 +1,56 @@ +package ch.qos.logback.classic.jul; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; + +public class JULHelper { + + + static public final boolean isRegularNonRootLogger(java.util.logging.Logger julLogger) { + if (julLogger == null) + return false; + return !julLogger.getName().equals(""); + } + + static public final boolean isRoot(java.util.logging.Logger julLogger) { + if (julLogger == null) + return false; + return julLogger.getName().equals(""); + } + + static public java.util.logging.Level asJULLevel(Level lbLevel) { + switch (lbLevel.levelInt) { + case Level.TRACE_INT: + return java.util.logging.Level.FINEST; + case Level.DEBUG_INT: + return java.util.logging.Level.FINE; + case Level.INFO_INT: + return java.util.logging.Level.INFO; + case Level.WARN_INT: + return java.util.logging.Level.WARNING; + case Level.ERROR_INT: + return java.util.logging.Level.SEVERE; + default: + throw new IllegalArgumentException("Unexpected level [" + lbLevel + "]"); + } + } + + static public String asJULLoggerName(String loggerName) { + if (Logger.ROOT_LOGGER_NAME.equals(loggerName)) + return ""; + else + return loggerName; + } + + static public java.util.logging.Logger asJULLogger(String loggerName) { + String julLoggerName = asJULLoggerName(loggerName); + return java.util.logging.Logger.getLogger(julLoggerName); + } + + static public java.util.logging.Logger asJULLogger(Logger logger) { + return asJULLogger(logger.getName()); + } + +} + + diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/jul/LevelChangePropagator.java b/logback-classic/src/main/java/ch/qos/logback/classic/jul/LevelChangePropagator.java new file mode 100644 index 0000000..adfe07c --- /dev/null +++ b/logback-classic/src/main/java/ch/qos/logback/classic/jul/LevelChangePropagator.java @@ -0,0 +1,105 @@ +/** + * 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.jul; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.LoggerContextListener; +import ch.qos.logback.core.spi.ContextAwareBase; +import ch.qos.logback.core.spi.LifeCycle; + +import java.util.Enumeration; +import java.util.List; +import java.util.logging.LogManager; + + +/** + * Propagate level changes made to a logback logger into the equivalent logger in j.u.l. + */ +public class LevelChangePropagator extends ContextAwareBase implements LoggerContextListener, LifeCycle { + + boolean isStarted = false; + + boolean resetJUL = false; + + public void setResetJUL(boolean resetJUL) { + this.resetJUL = resetJUL; + } + + public boolean isResetResistant() { + return false; + } + + public void onStart(LoggerContext context) { + } + + public void onReset(LoggerContext context) { + } + + public void onStop(LoggerContext context) { + } + + public void onLevelChange(Logger logger, Level level) { + propagate(logger, level); + } + + private void propagate(Logger logger, Level level) { + addInfo("Propagating " + level + " level on " + logger + " onto the JUL framework"); + java.util.logging.Logger julLogger = JULHelper.asJULLogger(logger); + java.util.logging.Level julLevel = JULHelper.asJULLevel(level); + julLogger.setLevel(julLevel); + } + + public void resetJULLevels() { + LogManager lm = LogManager.getLogManager(); + + Enumeration e = lm.getLoggerNames(); + while (e.hasMoreElements()) { + String loggerName = (String) e.nextElement(); + java.util.logging.Logger julLogger = lm.getLogger(loggerName); + if (JULHelper.isRegularNonRootLogger(julLogger) && julLogger.getLevel() != null) { + addInfo("Setting **** level of jul logger [" + loggerName + "] to null"); + julLogger.setLevel(null); + } + } + } + + private void propagateExistingLoggerLevels() { + LoggerContext loggerContext = (LoggerContext) context; + List<Logger> loggerList = loggerContext.getLoggerList(); + for (Logger l : loggerList) { + if (l.getLevel() != null) { + propagate(l, l.getLevel()); + } + } + } + + public void start() { + if (resetJUL) { + resetJULLevels(); + } + propagateExistingLoggerLevels(); + + isStarted = true; + } + + public void stop() { + isStarted = false; + } + + public boolean isStarted() { + return isStarted; + } +} diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/jul/package.html b/logback-classic/src/main/java/ch/qos/logback/classic/jul/package.html new file mode 100644 index 0000000..6c24ec4 --- /dev/null +++ b/logback-classic/src/main/java/ch/qos/logback/classic/jul/package.html @@ -0,0 +1,9 @@ + +<html> + + +<body> + Logback <-> java.util.logging (JUL) integration. +</body> + +</html> \ No newline at end of file diff --git a/logback-classic/src/test/input/joran/jul/levelChangePropagator0.xml b/logback-classic/src/test/input/joran/jul/levelChangePropagator0.xml new file mode 100644 index 0000000..026462f --- /dev/null +++ b/logback-classic/src/test/input/joran/jul/levelChangePropagator0.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE configuration> + +<configuration debug="false"> + + <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"> + <resetJUL>true</resetJUL> + </contextListener> + <logger name="a.b.c" level="WARN" /> + <root level="TRACE"/> + +</configuration> diff --git a/logback-classic/src/test/input/joran/jul/levelChangePropagator1.xml b/logback-classic/src/test/input/joran/jul/levelChangePropagator1.xml new file mode 100644 index 0000000..cb73f2f --- /dev/null +++ b/logback-classic/src/test/input/joran/jul/levelChangePropagator1.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE configuration> + +<configuration debug="false"> + + <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/> + <logger name="a.b.c" level="WARN" /> + <root level="TRACE"/> + +</configuration> diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java index 2473580..513fe2f 100644 --- a/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java +++ b/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java @@ -19,23 +19,24 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({org.slf4j.impl.PackageTest.class, - ch.qos.logback.classic.PackageTest.class, - ch.qos.logback.classic.util.PackageTest.class, - ch.qos.logback.classic.control.PackageTest.class, - ch.qos.logback.classic.joran.PackageTest.class, - ch.qos.logback.classic.rolling.PackageTest.class, - ch.qos.logback.classic.jmx.PackageTest.class, - ch.qos.logback.classic.boolex.PackageTest.class, - ch.qos.logback.classic.selector.PackageTest.class, - ch.qos.logback.classic.html.PackageTest.class, - ch.qos.logback.classic.net.PackageTest.class, - ch.qos.logback.classic.pattern.PackageTest.class, - ch.qos.logback.classic.encoder.PackageTest.class, - ch.qos.logback.classic.db.PackageTest.class, - ch.qos.logback.classic.spi.PackageTest.class, - ch.qos.logback.classic.turbo.PackageTest.class, - ch.qos.logback.classic.sift.PackageTest.class, - ch.qos.logback.classic.issue.PackageTest.class}) + ch.qos.logback.classic.PackageTest.class, + ch.qos.logback.classic.util.PackageTest.class, + ch.qos.logback.classic.control.PackageTest.class, + ch.qos.logback.classic.joran.PackageTest.class, + ch.qos.logback.classic.rolling.PackageTest.class, + ch.qos.logback.classic.jmx.PackageTest.class, + ch.qos.logback.classic.boolex.PackageTest.class, + ch.qos.logback.classic.selector.PackageTest.class, + ch.qos.logback.classic.html.PackageTest.class, + ch.qos.logback.classic.net.PackageTest.class, + ch.qos.logback.classic.pattern.PackageTest.class, + ch.qos.logback.classic.encoder.PackageTest.class, + ch.qos.logback.classic.db.PackageTest.class, + ch.qos.logback.classic.spi.PackageTest.class, + ch.qos.logback.classic.turbo.PackageTest.class, + ch.qos.logback.classic.sift.PackageTest.class, + ch.qos.logback.classic.jul.PackageTest.class, + ch.qos.logback.classic.issue.PackageTest.class}) public class AllClassicTest { } diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java index 6512023..8f82d6c 100644 --- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java +++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java @@ -13,15 +13,14 @@ */ package ch.qos.logback.classic.joran; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.logging.LogManager; +import ch.qos.logback.classic.jul.JULHelper; +import ch.qos.logback.core.util.StatusPrinter; import org.junit.Test; import org.slf4j.MDC; @@ -41,6 +40,8 @@ import ch.qos.logback.core.read.ListAppender; import ch.qos.logback.core.status.StatusChecker; import ch.qos.logback.core.testUtil.StringListAppender; +import static org.junit.Assert.*; + public class JoranConfiguratorTest { LoggerContext loggerContext = new LoggerContext(); @@ -309,8 +310,50 @@ public class JoranConfiguratorTest { StatusChecker checker = new StatusChecker(loggerContext); assertTrue(checker.isErrorFree()); } - + void verifyJULLevel(String loggerName, Level expectedLevel) { + LogManager lm = LogManager.getLogManager(); + + java.util.logging.Logger julLogger = JULHelper.asJULLogger(loggerName); + + java.util.logging.Level julLevel = julLogger.getLevel(); + + if(expectedLevel == null) { + assertNull(julLevel); + } else { + assertEquals(JULHelper.asJULLevel(expectedLevel), julLevel); + } + + + } + + @Test + public void levelChangePropagator0() throws JoranException, IOException, + InterruptedException { + java.util.logging.Logger.getLogger("xx").setLevel(java.util.logging.Level.INFO); + String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX + + "/jul/levelChangePropagator0.xml"; + configure(configFileAsStr); + StatusChecker checker = new StatusChecker(loggerContext); + assertTrue(checker.isErrorFree()); + verifyJULLevel("xx", null); + verifyJULLevel("a.b.c", Level.WARN); + verifyJULLevel(Logger.ROOT_LOGGER_NAME, Level.TRACE); + } + + @Test + public void levelChangePropagator1() throws JoranException, IOException, + InterruptedException { + java.util.logging.Logger.getLogger("xx").setLevel(java.util.logging.Level.INFO); + String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX + + "/jul/levelChangePropagator1.xml"; + configure(configFileAsStr); + StatusChecker checker = new StatusChecker(loggerContext); + assertTrue(checker.isErrorFree()); + verifyJULLevel("xx", Level.INFO); + verifyJULLevel("a.b.c", Level.WARN); + verifyJULLevel(Logger.ROOT_LOGGER_NAME, Level.TRACE); + } } diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/jul/LevelChangePropagatorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/jul/LevelChangePropagatorTest.java new file mode 100644 index 0000000..4f4eb06 --- /dev/null +++ b/logback-classic/src/test/java/ch/qos/logback/classic/jul/LevelChangePropagatorTest.java @@ -0,0 +1,59 @@ +/** + * 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.jul; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +public class LevelChangePropagatorTest { + LoggerContext loggerContext = new LoggerContext(); + LevelChangePropagator levelChangePropagator = new LevelChangePropagator(); + + @Before + public void setUp() { + levelChangePropagator.setContext(loggerContext); + loggerContext.addListener(levelChangePropagator); + } + + void checkLevelChange(String loggerName, Level level) { + Logger logger = loggerContext.getLogger(loggerName); + logger.setLevel(level); + java.util.logging.Logger julLogger = JULHelper.asJULLogger(logger); + java.util.logging.Level julLevel = JULHelper.asJULLevel(level); + + assertEquals(julLevel, julLogger.getLevel()); + + + } + + @Test + public void smoke() { + checkLevelChange("a", Level.INFO); + checkLevelChange("a.b", Level.DEBUG); + + } + + @Test + public void root() { + checkLevelChange(Logger.ROOT_LOGGER_NAME, Level.TRACE); + } + +} diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/jul/PackageTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/jul/PackageTest.java new file mode 100644 index 0000000..d47f9f6 --- /dev/null +++ b/logback-classic/src/test/java/ch/qos/logback/classic/jul/PackageTest.java @@ -0,0 +1,23 @@ +/** + * 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.jul; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({LevelChangePropagatorTest.class}) +public class PackageTest { +} \ No newline at end of file diff --git a/logback-site/src/site/pages/documentation.html b/logback-site/src/site/pages/documentation.html index 53da26f..3665b26 100644 --- a/logback-site/src/site/pages/documentation.html +++ b/logback-site/src/site/pages/documentation.html @@ -125,6 +125,11 @@ en Production - Les fichiers de logs</a> by Cyrille Le Clerc </li> + <li> + <a + href="http://blog.courtine.org/2010/09/13/logback-ou-log4j/">Logback + ou Log4J?</a> by Benoit Courtine + </li> </ul> diff --git a/logback-site/src/site/pages/manual/appenders.html b/logback-site/src/site/pages/manual/appenders.html index 3944286..29c198f 100644 --- a/logback-site/src/site/pages/manual/appenders.html +++ b/logback-site/src/site/pages/manual/appenders.html @@ -151,7 +151,7 @@ public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachabl access to the appender. </p> - <p>Since such syncronization is not always appropriate, logback + <p>Since such synchronization is not always appropriate, logback ships with <a href="../xref/ch/qos/logback/core/UnsynchronizedAppenderBase.html"><code>ch.qos.logback.core.UnsynchronizedAppenderBase</code></a> which is very similar to the <a @@ -243,7 +243,7 @@ public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachabl provides basic services that other appenders build upon. Users do not usually instantiate <code>OutputStreamAppender</code> objects directly. Since in general the <code>java.io.OutputStream</code> - type cannot be conveninetly mapped to a string, as there is no way + type cannot be conveniently mapped to a string, as there is no way to specify the target <code>OutputStream</code> object in a configuration script. Simply put, you cannot configure a <code>OutputStreamAppender</code> from a configuration file. @@ -274,14 +274,14 @@ public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachabl <p>Given the structure of current hard drives and performance tests we have conducted, it appears that turning off immediate flushing or buffering of character to byte conversions have rather small impact - on performance. As such, as of logback vesion 0.9.19, the <span + on performance. As such, as of logback version 0.9.19, the <span class="option">ImmediateFlush</span>, <span class="option">BufferedIO</span> and <span class="option">BufferSize</span> properties have been removed without replacement. </p> - <p>The <code>OutputStreamAppender</code> is the superclass of three other + <p>The <code>OutputStreamAppender</code> is the super-class of three other appenders, namely <code>ConsoleAppender</code>, <code>FileAppender</code> which in turn is the super class of <code>RollingFileAppender</code>. The next figure illustrates the @@ -936,7 +936,7 @@ public interface RollingPolicy extends LifeCycle { omitted. <p>By setting the <span class="option">file</span> property - of the containig <code>FileAppender</code>, you can decouple + of the containing <code>FileAppender</code>, you can decouple the location of the active log file and the location of the archived log files. The current logs will be always targeted at the file specified by the <span class="option">file</span> @@ -1324,7 +1324,7 @@ public interface TriggeringPolicy<E> extends LifeCycle { <p>The most widely-used triggering policy, namely <code>TimeBasedRollingPolicy</code> which also doubles as a - rolliging policy, was already <a + rolling policy, was already <a href="#TimeBasedRollingPolicy">discussed earlier</a> along with other rolling policies. </p> @@ -2224,7 +2224,7 @@ Context ctx = new InitialContext(env);</pre> same value so that the same buffer is used for all events. </p> - <p>By specifiying a discriminator other than the default + <p>By specifying a discriminator other than the default one, it would be possible to receive email messages containing a events pertaining to a particular user, user session or client IP address. @@ -2552,7 +2552,7 @@ logger.error(<b>notifyAdminMarker</b>, new Exception("Just testing"));</pre> <p>The next configuration file will cause outgoing emails to be - sent only in presensce of events bearing the NOTIFY_ADMIN or the + sent only in presence of events bearing the NOTIFY_ADMIN or the TRANSACTION_FAILURE marker. </p> @@ -2676,7 +2676,7 @@ logger.error(<b>notifyAdminMarker</b>, <p>The next example illustrates the use of<a href="../xref/ch/qos/logback/classic/sift/MDCBasedDiscriminator.html">MDCBasedDiscriminator</a> - in conjuction with the MDC key named "req.remoteHost", assumed to + in conjunction with the MDC key named "req.remoteHost", assumed to contain the IP address of the remote host accessing a fictitious application. In a web-application, you could use <a href="mdc.html#mis">MDCInsertingServletFilter</a> to populate MDC diff --git a/logback-site/src/site/pages/manual/configuration.html b/logback-site/src/site/pages/manual/configuration.html index 2d0db3e..0d70252 100644 --- a/logback-site/src/site/pages/manual/configuration.html +++ b/logback-site/src/site/pages/manual/configuration.html @@ -1699,6 +1699,62 @@ fileName=myApp.log </ul> + <!-- ==================== ContextListener =================== --> + <h2><a name="contextListener" href="#contextListener">Adding a context listener</a></h2> + + <p>Instances of the <a + href="../xref/ch/qos/logback/classic/spi/LoggerContextListener.html">LoggerContextListener</a> + interface listen to events pertaining to the lifecycle of a logger + context. + </p> + + + <p><code>JMXConfigurator</code> is one implementation of the + <code>LoggerContextListener</code> interface. It is desribed in a <a + href="jmxConfig.html">subsequent chapter</a>. + </p> + + <h3><a name="LevelChangePropagator" + href="#LevelChangePropagator">LevelChangePropagator</a></h3> + + <p>As of version 0.9.25, logback-classic ships with <a + href="../xref/ch/qos/logback/classic/jul/LevelChangePropagator.html">LevelChangePropagator</a>, + an implementation of <code>LoggerContextListener</code> which + propagates changes made to the level of any logback-classic logger + onto the java.util.logging framework. Such propagation eliminates + the performance impact of disabled log statements. Instances of <a + href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/logging/LogRecord.html?is-external=true">LogRecord</a> + will be sent to logback (via SLF4J) only for enabled log + statements. This makes it reasonable for real-world applications to + use the <a + href="http://www.slf4j.org/legacy.html#jul-to-slf4j">jul-to-slf4j</a> + bridge. + </p> + + + <p>The contextListener element can be used to install <code>LevelChangePropagator</code> as shown next.</p> + + <pre class="prettyprint source"><configuration debug="false"> + <b><contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/></b> + .... +</configuration></pre> + + <p>Setting the <span class="option">resetJUL</span> propery of + LevelChangePropagator will reset all previous level configurations + of all j.u.l. loggers. Previously installed handlers however will be + left untouched.</p> + + <pre class="prettyprint source"><configuration debug="false"> + <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"> + <b><resetJUL>true</resetJUL></b> + </contextListener> + .... +</configuration></pre> + <p> + </p> + + + <script src="../templates/footer.js" type="text/javascript"></script> </div> </body> ----------------------------------------------------------------------- Summary of changes: .../logback/classic/joran/JoranConfigurator.java | 12 +-- .../joran/action/JMXConfiguratorAction.java | 2 +- .../joran/action/LoggerContextListenerAction.java | 12 ++- .../classic/joran/action/RootLoggerAction.java | 1 - .../java/ch/qos/logback/classic/jul/JULHelper.java | 56 +++++++++++ .../logback/classic/jul/LevelChangePropagator.java | 105 ++++++++++++++++++++ .../java/ch/qos/logback/classic/jul/package.html | 9 ++ .../input/joran/jul/levelChangePropagator0.xml | 12 +++ .../input/joran/jul/levelChangePropagator1.xml | 10 ++ .../ch/qos/logback/classic/AllClassicTest.java | 35 ++++--- .../classic/joran/JoranConfiguratorTest.java | 53 +++++++++- .../classic/jul/LevelChangePropagatorTest.java | 59 +++++++++++ .../classic/{control => jul}/PackageTest.java | 5 +- logback-site/src/site/pages/documentation.html | 5 + logback-site/src/site/pages/manual/appenders.html | 18 ++-- .../src/site/pages/manual/configuration.html | 56 +++++++++++ 16 files changed, 404 insertions(+), 46 deletions(-) create mode 100644 logback-classic/src/main/java/ch/qos/logback/classic/jul/JULHelper.java create mode 100644 logback-classic/src/main/java/ch/qos/logback/classic/jul/LevelChangePropagator.java create mode 100644 logback-classic/src/main/java/ch/qos/logback/classic/jul/package.html create mode 100644 logback-classic/src/test/input/joran/jul/levelChangePropagator0.xml create mode 100644 logback-classic/src/test/input/joran/jul/levelChangePropagator1.xml create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/jul/LevelChangePropagatorTest.java copy logback-classic/src/test/java/ch/qos/logback/classic/{control => jul}/PackageTest.java (88%) hooks/post-receive -- Logback: the generic, reliable, fast and flexible logging framework.
participants (1)
-
git-noreply@pixie.qos.ch