[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-78-g7ffb4f8
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Thu Mar 11 23:16:29 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 7ffb4f83eb56a595d6757c58aae0812d2686ac4d (commit)
from c7af050b93defa5beb51c3d031ddcf85909719d7 (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=7ffb4f83eb56a595d6757c58aae0812d2686ac4d
http://github.com/ceki/logback/commit/7ffb4f83eb56a595d6757c58aae0812d2686ac4d
commit 7ffb4f83eb56a595d6757c58aae0812d2686ac4d
Author: Ceki Gulcu <ceki at qos.ch>
Date: Thu Mar 11 23:15:53 2010 +0100
- improving the docs
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java
index 58851ac..ac2d714 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java
@@ -153,9 +153,9 @@ public class ReconfigureOnChangeTest {
// however, there should be some effective resets
String failMsg = "effective=" + effectiveResets + ", expected="
+ expectedReconfigurations;
-
- //
- if (!(Env.isJDK6OrHigher())) {
+
+ // we can't have the test succeed under JDK 1.5, punt and require 1.6+
+ if (Env.isJDK6OrHigher()) {
assertTrue(failMsg,
(effectiveResets * 1.3) >= (expectedReconfigurations * 1.0));
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/encoder/LayoutWrappingEncoder.java b/logback-core/src/main/java/ch/qos/logback/core/encoder/LayoutWrappingEncoder.java
index 32ea60d..00de2e3 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/encoder/LayoutWrappingEncoder.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/encoder/LayoutWrappingEncoder.java
@@ -93,7 +93,7 @@ public class LayoutWrappingEncoder<E> extends EncoderBase<E> {
return s.getBytes(charset.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(
- "An existing charser cannot possibly be unsupported.");
+ "An existing charset cannot possibly be unsupported.");
}
}
}
diff --git a/logback-examples/src/main/java/chapters/appenders/conf/logback-HtmlToConsole.xml b/logback-examples/src/main/java/chapters/appenders/conf/logback-HtmlToConsole.xml
index a762945..2e3fd77 100644
--- a/logback-examples/src/main/java/chapters/appenders/conf/logback-HtmlToConsole.xml
+++ b/logback-examples/src/main/java/chapters/appenders/conf/logback-HtmlToConsole.xml
@@ -1,15 +1,17 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder class="ch.qos.logback.classic.html.HTMLLayout">
- <cssBuilder class="ch.qos.logback.core.helpers.CssBuilder">
- <url>path_to_StyleFile.css</url>
- </cssBuilder>
- <Pattern>%-4relative [%thread] %-5level - %msg%n</Pattern>
+ <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <cssBuilder class="ch.qos.logback.classic.html.UrlCssBuilder">
+ <url>path_to_StyleFile.css</url>
+ </cssBuilder>
+ <pattern>%-4relative [%thread] %-5level - %msg%n</pattern>
+ </layout>
</encoder>
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
diff --git a/logback-examples/src/main/java/chapters/filters/levelFilterConfig.xml b/logback-examples/src/main/java/chapters/filters/levelFilterConfig.xml
index 9b514f9..f99902f 100644
--- a/logback-examples/src/main/java/chapters/filters/levelFilterConfig.xml
+++ b/logback-examples/src/main/java/chapters/filters/levelFilterConfig.xml
@@ -7,9 +7,9 @@
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
- <layout class="ch.qos.logback.classic.PatternLayout">
+ <encoder>
<pattern>%-4relative [%thread] %-5level %logger{30} - %msg%n</pattern>
- </layout>
+ </encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
diff --git a/logback-examples/src/main/java/chapters/filters/sampleFilterConfig.xml b/logback-examples/src/main/java/chapters/filters/sampleFilterConfig.xml
index 203b247..b13389a 100644
--- a/logback-examples/src/main/java/chapters/filters/sampleFilterConfig.xml
+++ b/logback-examples/src/main/java/chapters/filters/sampleFilterConfig.xml
@@ -1,14 +1,13 @@
<configuration>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <Filter class="chapters.filters.SampleFilter" />
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <filter class="chapters.filters.SampleFilter" />
- <layout class="ch.qos.logback.classic.PatternLayout">
+ <encoder>
<pattern>
%-4relative [%thread] %-5level %logger - %msg%n
</pattern>
- </layout>
+ </encoder>
</appender>
<root>
diff --git a/logback-examples/src/main/java/chapters/filters/thresholdFilterConfig.xml b/logback-examples/src/main/java/chapters/filters/thresholdFilterConfig.xml
index f7a38b8..294b017 100644
--- a/logback-examples/src/main/java/chapters/filters/thresholdFilterConfig.xml
+++ b/logback-examples/src/main/java/chapters/filters/thresholdFilterConfig.xml
@@ -7,9 +7,9 @@
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
- <layout>
+ <encoder>
<pattern>%-4relative [%thread] %-5level %logger{30} - %msg%n</pattern>
- </layout>
+ </encoder>
</appender>
diff --git a/logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java b/logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java
index fac16d7..4fc375f 100644
--- a/logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java
+++ b/logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java
@@ -33,10 +33,12 @@ public class ExceptionEvaluatorExample {
lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
- StatusPrinter.print(lc);
+ // StatusPrinter will handle this
}
- for (int i = 0; i < 5; i++) {
- if (i == 3) {
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+
+ for (int i = 0; i < 3; i++) {
+ if (i == 1) {
logger.debug("logging statement " + i, new TestException(
"do not display this"));
} else {
diff --git a/logback-examples/src/main/java/chapters/layouts/SampleLogging.java b/logback-examples/src/main/java/chapters/layouts/SampleLogging.java
index 5e7d55c..fe0b8de 100644
--- a/logback-examples/src/main/java/chapters/layouts/SampleLogging.java
+++ b/logback-examples/src/main/java/chapters/layouts/SampleLogging.java
@@ -23,15 +23,19 @@ import ch.qos.logback.core.util.StatusPrinter;
public class SampleLogging {
- public static void main(String[] args) throws JoranException {
+ public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(SampleLogging.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator configurator = new JoranConfigurator();
- lc.reset();
- configurator.setContext(lc);
- configurator.doConfigure(args[0]);
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ lc.reset();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ // StatusPrinter will handle this
+ }
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
logger.debug("Everything's going well");
diff --git a/logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java b/logback-examples/src/main/java/chapters/layouts/TrivialMain.java
similarity index 51%
copy from logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java
copy to logback-examples/src/main/java/chapters/layouts/TrivialMain.java
index fac16d7..ff0dcbe 100644
--- a/logback-examples/src/main/java/chapters/layouts/ExceptionEvaluatorExample.java
+++ b/logback-examples/src/main/java/chapters/layouts/TrivialMain.java
@@ -1,15 +1,15 @@
/**
* 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.
+ * 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 chapters.layouts;
@@ -21,27 +21,28 @@ import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
-public class ExceptionEvaluatorExample {
-
- public static void main(String[] args) {
- Logger logger = LoggerFactory.getLogger(ExceptionEvaluatorExample.class);
+public class TrivialMain {
+ public static void main(String[] args) throws InterruptedException {
+ Logger logger = LoggerFactory.getLogger(TrivialMain.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-
+
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
- StatusPrinter.print(lc);
+ // StatusPrinter will handle this
}
- for (int i = 0; i < 5; i++) {
- if (i == 3) {
- logger.debug("logging statement " + i, new TestException(
- "do not display this"));
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+
+ for (int i = 0; i < 6; i++) {
+ if (i % 5 == 0) {
+ logger.warn("a warning message " + i);
} else {
- logger.debug("logging statement " + i, new Exception("display"));
+ logger.debug("hello world number" + i);
}
}
+ logger.error("Finish off with fireworks", new Exception("Just testing"));
}
}
\ No newline at end of file
diff --git a/logback-examples/src/main/java/chapters/layouts/exceptionEvaluatorConfig.xml b/logback-examples/src/main/java/chapters/layouts/exceptionEvaluatorConfig.xml
index 1f51577..7643768 100644
--- a/logback-examples/src/main/java/chapters/layouts/exceptionEvaluatorConfig.xml
+++ b/logback-examples/src/main/java/chapters/layouts/exceptionEvaluatorConfig.xml
@@ -1,16 +1,16 @@
<configuration>
<evaluator name="DISPLAY_EX_EVAL">
- <Expression>throwable != null && throwable instanceof chapters.layouts.TestException</Expression>
+ <expression>throwable != null && throwable instanceof chapters.layouts.TestException</expression>
</evaluator>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%-4relative [%thread] %-5level - %msg%n%ex{full, DISPLAY_EX_EVAL}</Pattern>
- </layout>
+ <encoder>
+ <pattern>%msg%n%xEx{full, DISPLAY_EX_EVAL}</pattern>
+ </encoder>
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
diff --git a/logback-examples/src/main/java/chapters/layouts/htmlLayoutConfig1.xml b/logback-examples/src/main/java/chapters/layouts/htmlLayoutConfig1.xml
new file mode 100644
index 0000000..3dfd5b6
--- /dev/null
+++ b/logback-examples/src/main/java/chapters/layouts/htmlLayoutConfig1.xml
@@ -0,0 +1,14 @@
+<configuration>
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <pattern>%relative%thread%mdc%level%logger%msg</pattern>
+ </layout>
+ </encoder>
+ <file>test.html</file>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
\ No newline at end of file
diff --git a/logback-examples/src/main/java/chapters/layouts/mySampleConverterConfig.xml b/logback-examples/src/main/java/chapters/layouts/mySampleConverterConfig.xml
index 048eb24..bcc3c14 100644
--- a/logback-examples/src/main/java/chapters/layouts/mySampleConverterConfig.xml
+++ b/logback-examples/src/main/java/chapters/layouts/mySampleConverterConfig.xml
@@ -1,15 +1,15 @@
<configuration>
- <conversionRule conversionWord="sample" converterClass="chapters.layouts.MySampleConverter" />
+ <conversionRule conversionWord="sample"
+ converterClass="chapters.layouts.MySampleConverter" />
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%-4relative [%thread] %sample - %msg%n</Pattern>
- </layout>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%-4relative [%thread] %sample - %msg%n</pattern>
+ </encoder>>
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
diff --git a/logback-site/src/site/pages/manual/filters.html b/logback-site/src/site/pages/manual/filters.html
index b61a452..82ca505 100644
--- a/logback-site/src/site/pages/manual/filters.html
+++ b/logback-site/src/site/pages/manual/filters.html
@@ -132,13 +132,13 @@ public class SampleFilter extends Filter>ILoggingEvent> {
<pre class="prettyprint source"><configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <b><Filter class="chapters.filters.SampleFilter" /></b>
+ <b><filter class="chapters.filters.SampleFilter" /></b>
- <layout class="ch.qos.logback.classic.PatternLayout">
+ <encoder>
<pattern>
%-4relative [%thread] %-5level %logger - %msg%n
</pattern>
- </layout>
+ </encoder>
</appender>
<root>
@@ -185,18 +185,17 @@ public class SampleFilter extends Filter>ILoggingEvent> {
<em>Example 6.<span class="autoEx"/>: Sample LevelFilter configuration (logback-examples/src/main/java/chapters/filters/levelFilterConfig.xml)</em>
<pre class="prettyprint source"><configuration>
- <appender name="CONSOLE"
- class="ch.qos.logback.core.ConsoleAppender">
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<b><filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter></b>
- <layout>
+ <encoder>
<pattern>
%-4relative [%thread] %-5level %logger{30} - %msg%n
</pattern>
- </layout>
+ </encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
@@ -223,11 +222,11 @@ public class SampleFilter extends Filter>ILoggingEvent> {
<b><filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter></b>
- <layout>
+ <encoder>
<pattern>
%-4relative [%thread] %-5level %logger{30} - %msg%n
</pattern>
- </layout>
+ </encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
@@ -401,8 +400,7 @@ public class SampleFilter extends Filter>ILoggingEvent> {
<pre class="prettyprint source longline"><configuration>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<b><filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator> <!-- defaults to type ch.qos.logback.classic.boolex.JaninoEventEvaluator -->
<expression><span class="green">message.contains("billing")</span></expression>
@@ -410,11 +408,11 @@ public class SampleFilter extends Filter>ILoggingEvent> {
<OnMismatch>NEUTRAL</OnMismatch>
<OnMatch>DENY</OnMatch>
</filter></b>
- <layout>
+ <encoder>
<pattern>
%-4relative [%thread] %-5level %logger - %msg%n
</pattern>
- </layout>
+ </encoder>
</appender>
<root level="INFO">
@@ -524,9 +522,9 @@ java chapters.filters.FilterEvents src/main/java/chapters/filters/basicConfigura
<OnMismatch>NEUTRAL</OnMismatch>
<OnMatch>DENY</OnMatch>
</filter>
- <layout>
+ <encoder>
<pattern>%-4relative [%thread] %-5level %logger - %msg%n</pattern>
- </layout>
+ </encoder>
</appender>
<root level="DEBUG">
@@ -662,13 +660,12 @@ public class SampleTurboFilter extends TurboFilter {
<Marker>sample</Marker>
</turboFilter></b>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
<pattern>
%-4relative [%thread] %-5level %logger - %msg%n
</pattern>
- </layout>
+ </encoder>
</appender>
<root>
@@ -708,12 +705,12 @@ configuration (logback-examples/src/main/java/chapters/filters/turboFilters.xml)
</turboFilter>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%date [%thread] %-5level %logger - %msg%n</Pattern>
- </layout>
+ <encoder>
+ <pattern>%date [%thread] %-5level %logger - %msg%n</pattern>
+ </encoder>
</appender>
- <root level="info">
+ <root level="INFO">
<appender-ref ref="console" />
</root>
</configuration></pre>
@@ -826,12 +823,12 @@ configuration (logback-examples/src/main/java/chapters/filters/duplicateMessage.
<b><turboFilter class="ch.qos.logback.classic.turbo.DuplicateMessageFilter"/></b>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%date [%thread] %-5level %logger - %msg%n</Pattern>
- </layout>
+ <encoder>
+ <pattern>%date [%thread] %-5level %logger - %msg%n</pattern>
+ </encoder>
</appender>
- <root level="info">
+ <root level="INFO">
<appender-ref ref="console" />
</root>
</configuration></pre>
@@ -897,20 +894,19 @@ configuration (logback-examples/src/main/java/chapters/filters/duplicateMessage.
<em>Example 6.<span class="autoEx"/>: Access Evaluator (logback-examples/src/main/java/chapters/filters/accessEventEvaluator.xml)</em>
<pre class="prettyprint source"><configuration>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<b><filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator name="myEval">
<expression>event.getStatusCode() == 404</expression>
</evaluator>
- <OnMismatch>NEUTRAL</OnMismatch>
- <OnMatch>ACCEPT</OnMatch>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>ACCEPT</onMatch>
</filter></b>
- <layout class="ch.qos.logback.access.PatternLayout">
+ <encoder>
<pattern>
%h %l %u %t %r %s %b
</pattern>
- </layout>
+ </encoder>
</appender>
<appender-ref ref="STDOUT" />
@@ -924,27 +920,26 @@ configuration (logback-examples/src/main/java/chapters/filters/duplicateMessage.
<em>Example 6.10: Access Evaluator (logback-examples/src/main/java/chapters/filters/accessEventEvaluator2.xml)</em>
<pre class="prettyprint source"><configuration>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<b><filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator name="Eval404">
<expression>event.getStatusCode() == 404</expression>
</evaluator>
- <OnMismatch>NEUTRAL</OnMismatch>
- <OnMatch>ACCEPT</OnMatch>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>ACCEPT</onMatch>
</filter>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator name="EvalCSS">
<expression>event.getRequestURI().contains("css")</expression>
</evaluator>
- <OnMismatch>NEUTRAL</OnMismatch>
- <OnMatch>DENY</OnMatch>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>DENY</onMatch>
</filter></b>
- <layout class="ch.qos.logback.access.PatternLayout">
+ <encoder>
<pattern>
%h %l %u %t %r %s %b
</pattern>
- </layout>
+ </encoder>
</appender>
<appender-ref ref="STDOUT" />
diff --git a/logback-site/src/site/pages/manual/layouts.html b/logback-site/src/site/pages/manual/layouts.html
index 25ffd9b..7021214 100644
--- a/logback-site/src/site/pages/manual/layouts.html
+++ b/logback-site/src/site/pages/manual/layouts.html
@@ -848,6 +848,7 @@ Caller+2 at mainPackage.ConfigTester.main(ConfigTester.java:38)</pre>
<tr class="alt">
<td align="center">
+ <a name="xThrowable" href="#xThrowable">
<b>xEx</b>{<em>length</em>} <br />
<b>xException</b>{<em>length</em>} <br />
<b>xThrowable</b>{<em>length</em>} <br />
@@ -855,6 +856,7 @@ Caller+2 at mainPackage.ConfigTester.main(ConfigTester.java:38)</pre>
<b>xEx</b>{length, evaluator-1, ..., evaluator-n} <br />
<b>xException</b>{length, evaluator-1, ..., evaluator-n} <br />
<b>xThrowable</b>{length, evaluator-1, ..., evaluator-n}
+ </a>
</td>
<td>
@@ -1274,27 +1276,31 @@ Caller+2 at mainPackage.ConfigTester.main(ConfigTester.java:38)</pre>
</em>
<pre class="prettyprint source"><configuration>
<b><evaluator name="DISP_CALLER_EVAL">
- <Expression>logger.getName().contains("chapters.layouts") &amp;&amp; \
- message.contains("who calls thee")</Expression>
+ <expression>logger.contains("chapters.layouts") &amp;&amp; \
+ message.contains("who calls thee")</expression>
</evaluator></b>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%-4relative [%thread] %-5level - %msg%n<b>%caller{2, DISP_CALLER_EVAL}</b>
- </Pattern>
- </layout>
+ <encoder>
+ <pattern>
+ %-4relative [%thread] %-5level - %msg%n<b>%caller{2, DISP_CALLER_EVAL}</b>
+ </pattern>
+ </encoder>
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration></pre>
- <p>Due to XML encoding rules, the & character cannot be
- written as is, and needs to be escaped as &amp;.</p>
+ <p>The above evaluation expression matches events which emanate
+ from logger with a name containing the string "chapters.layouts"
+ and the message containing the string "who calls thee". Due to XML
+ encoding rules, the & character cannot be written as is, and
+ needs to be escaped as &amp;.</p>
- <p>The above configuration file is designed to be accompanied by
- the following custom-tailored code.</p>
+ <p>The following class makes use of some of the characteristics
+ mentioned in above configuration file.</p>
<p><em>
Example 5.2: Sample usage of EventEvaluators
@@ -1302,7 +1308,7 @@ Caller+2 at mainPackage.ConfigTester.main(ConfigTester.java:38)</pre>
(logback-examples/src/main/java/chapters/layouts/CallerEvaluatorExample.java)</a>
</em>
</p>
- <pre class="prettyprint source">package chapters.layouts;
+ <pre class="prettyprint source">package <b>chapters.layouts</b>;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1329,7 +1335,7 @@ public class CallerEvaluatorExample {
for (int i = 0; i < 5; i++) {
if (i == 3) {
- logger.debug("who calls thee?");
+ logger.debug(<b>"who calls thee</b>?");
} else {
logger.debug("I know me " + i);
}
@@ -1337,14 +1343,9 @@ public class CallerEvaluatorExample {
}
}</pre>
- <p>The <em>CallerEvaluatorExample</em> application does nothing
- particularly fancy. Five logging requests are issued, the third
- one being different from the others.
- </p>
-
- <p>When a logging request is issued, the corresponding logging
- event is evaluated. The third request matches the evaluation
- criteria, causing its caller data to be displayed.
+ <p>The above application does nothing particularly fancy. Five
+ logging requests are issued, the third one emitting the message
+ "who calls theee?"
</p>
<p>The command</p>
@@ -1360,6 +1361,15 @@ public class CallerEvaluatorExample {
Caller+0 at chapters.layouts.CallerEvaluatorExample.main(CallerEvaluatorExample.java:28)
0 [main] DEBUG - I know me 4</pre></div>
+
+ <p>When a logging request is issued, the corresponding logging
+ event is evaluated. Only the third logging event matches the
+ evaluation criteria, causing its caller data to be displayed. For
+ other logging events, the evaluation criteria do not match and no
+ caller data is printed.
+ </p>
+
+
<p>One can change the expression to correspond a real world
scenario. For instance, one could combine the logger name and
request level. Thus, logging requests of level <em>WARN</em> and
@@ -1368,19 +1378,23 @@ Caller+0 at chapters.layouts.CallerEvaluatorExample.main(CallerEvaluatorExampl
displayed.
</p>
- <p><b>Important:</b> With the <em>caller</em> conversion word, the
- data is displayed when <em>the expression evaluates to
+ <p><b>Important:</b> With the <em>caller</em> conversion word,
+ caller data is output when <em>the expression evaluates to
<b>true</b>.</em></p>
<p>Let us consider at a different situation. When exceptions are
- included in a logging request, their stack trace is usually
- displayed. However, in some cases, one might want to supress the
- stack trace of some specific exception.
+ included in a logging request, their stack trace is also
+ output. However, one might want to supress the stack trace for
+ some specific exceptions.
</p>
- <p>The java code shown below creates five log requests, each with
- an exception. However, it so happends that we do not wish the
- stack trace of the third request to be output.</p>
+ <p>The java code shown below creates three log requests, each with
+ an exception. The second exception different from the others
+ contains the string "do not display this" and conttrary to the
+ others it is of type
+ <code>chapters.layouts.TestException</code>. As its message
+ commands, let us now prevent the third exception from being
+ printed.</p>
<p><em>
Example 5.2: Sample usage of EventEvaluators
@@ -1407,12 +1421,15 @@ public class ExceptionEvaluatorExample {
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
+ lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
- StatusPrinter.print(lc);
+ // StatusPrinter will handle this
}
- for (int i = 0; i < 5; i++) {
- if (i == 3) {
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+
+ for (int i = 0; i < 3; i++) {
+ if (i == 1) {
logger.debug("logging statement " + i, new TestException(
"do not display this"));
} else {
@@ -1422,8 +1439,12 @@ public class ExceptionEvaluatorExample {
}
}</pre>
- <p>The following configuration will supress the stack trace of the
- third logging request.</p>
+ <p>In the next configuration file, the evaluation expression
+ matches events containing a throwable of type
+ <code>chapters.layouts.TextException</code>, precisely the type of
+ exceptions we wish to supress.
+ </p>
+
<em>
Example 5.3: Sample usage of EventEvaluators
(logback-examples/src/main/java/chapters/layouts/exceptionEvaluatorConfig.xml)
@@ -1431,16 +1452,14 @@ public class ExceptionEvaluatorExample {
<pre class="prettyprint source"><configuration>
<b><evaluator name="DISPLAY_EX_EVAL">
- <Expression>throwable != null &amp;&amp; throwable instanceof \
- chapters.layouts.TestException</Expression>
+ <expression>throwable != null &amp;&amp; throwable instanceof \
+ chapters.layouts.TestException</expression>
</evaluator></b>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%-4relative [%thread] %-5level - %msg%n<b>%ex{full, DISPLAY_EX_EVAL}</b>
- </Pattern>
- </layout>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder
+ <pattern>%msg%n<b>%ex{full, DISPLAY_EX_EVAL}</b></pattern>
+ </encoder>
</appender>
<root level="debug">
@@ -1453,18 +1472,41 @@ public class ExceptionEvaluatorExample {
request, the stack trace will be suppressed.
</p>
+ <p>Launching the command</p>
+
+ <p class="source">java chapters.layouts.ExceptionEvaluatorExample src/main/java/chapters/layouts/exceptionEvaluatorConfig.xml</p>
+
+ <p>will yield</p>
+
+<p class="source">logging statement 0
+java.lang.Exception: display
+ at chapters.layouts.ExceptionEvaluatorExample.main(ExceptionEvaluatorExample.java:43) [logback-examples-0.9.19.jar:na]
+logging statement 1
+logging statement 2
+java.lang.Exception: display
+ at chapters.layouts.ExceptionEvaluatorExample.main(ExceptionEvaluatorExample.java:43) [logback-examples-0.9.19.jar:na]</p>
+
+
+ <p>Notice how the second log statement has no stack trace. We
+ effectively supressed the stack trace for the
+ <code>TextException</code>. The text between square brackets at
+ the end of each stack trace line is <a
+ href="#xThrowable">packaging information</a> discussed
+ earlier.</p>
+
<p><b>Important:</b> With the <b><em>%ex</em></b> conversion
specifier, the stack trace is displayed when <em>the expression
evaluates to <b>false</b>.</em></p>
+
- <h3><a name="customConversionSpecifier"
+ <h2><a name="customConversionSpecifier"
href="#customConversionSpecifier">Creating a custom conversion
- specifier</a></h3>
+ specifier</a></h2>
- <p>Up to this point we have presented the built-inconversion
- specifiers of <code>PatternLayout</code>. But it is also possible
- to use a conversion specifier of your own making.</p>
+ <p>Up to this point we have presented the built-in conversion
+ words in <code>PatternLayout</code>. But it is also possible to
+ add conversion words of your own making.</p>
<p>Building a custom conversion specifier consists of two steps.
</p>
@@ -1541,24 +1583,24 @@ public class MySampleConverter extends ClassicConverter {
<em> Example 5.4: Sample Converter Example (src/main/java/chapters/layouts/mySampleConverterConfig.xml)</em>
<pre class="prettyprint source"><configuration>
- <b><conversionRule conversionWord="sample" converterClass="chapters.layouts.MySampleConverter" /></b>
+ <b><conversionRule conversionWord="sample"
+ converterClass="chapters.layouts.MySampleConverter" /></b>
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <b><Pattern>%-4relative [%thread] %sample - %msg%n</Pattern></b>
- </layout>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%-4relative [%thread] <b>%sample</b> - %msg%n</pattern>
+ </encoder
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration></pre>
- <p>In this configuration file, once the new conversion word has
- been declared, we can refert to it within a
- <code>PatternLayout</code> pattern, as if the custom conversion
- word had always been here.</p>
+ <p>Once the new conversion word has been declared in the
+ configuration file, we can refer to it within
+ <code>PatternLayout</code> pattern, as with any other
+ conversion word.</p>
<p>Given that ANSI terminal codes do not work on Windows, you can
view the results on non-Windows platforms such as Linux or
@@ -1573,9 +1615,9 @@ public class MySampleConverter extends ClassicConverter {
<p>Please note that the string "ERROR" is highlighted in red,
- which was somewhat the point of the exercise.</p>
+ which was the declared intent of the exercise.</p>
- <p>The intersted reader might want to take a look at other
+ <p>The reader might want to take a look at other
<code>Converter</code> implementations such as
<a href="../xref/ch/qos/logback/classic/pattern/MDCConverter.html">
<code>MDCConverter</code></a> to learn about more complex
@@ -1584,9 +1626,9 @@ public class MySampleConverter extends ClassicConverter {
- <h3>
+ <h2>
<a name="ClassicHTMLLayout" href="#ClassicHTMLLayout">HTMLLayout</a>
- </h3>
+ </h2>
<p><a
href="../xref/ch/qos/logback/classic/html/HTMLLayout.html"><code>HTMLLayout</code></a>
@@ -1597,7 +1639,7 @@ public class MySampleConverter extends ClassicConverter {
<p>Here is a sample output produced by <code>HTMLLayout</code>
using its default CSS stylesheet:</p>
- <img src="images/htmlLayout0.gif" alt="HTML Layout Sample Image"/>
+ <img src="images/chapters/layouts/htmlLayout0.gif" alt="HTML Layout Sample Image"/>
<p>The content of table columns are specified with the help of a
conversion pattern. See <a
@@ -1623,21 +1665,23 @@ public class MySampleConverter extends ClassicConverter {
<pre class="prettyprint source"><configuration debug="true">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
- <layout class="ch.qos.logback.classic.html.HTMLLayout">
- <b><pattern>%relative%thread%mdc%level%logger%msg</pattern></b>
- </layout>
- <File>/test.html</File>
+ <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <b><pattern>%relative%thread%mdc%level%logger%msg</pattern></b>
+ </layout>
+ </encoder>
+ <file>test.html</file>
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
</pre>
- <p>Launching the <code>TrivialMain</code> application listed below
- will create the file <em>test.html</em> on your local drive.</p>
-
+ <p>The next application logs a few messages finishing with an
+ exception.</p>
+
<pre class="prettyprint source">import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1646,7 +1690,7 @@ public class TrivialMain {
Logger logger = LoggerFactory.getLogger(TrivialMain.class);
for(int i = 0; i < 6; i ++) {
if(i % 5 == 0) {
- logger.info("an info message "+i);
+ logger.warn("a warning message "+i);
} else {
logger.debug("hello world number" +i);
}
@@ -1655,9 +1699,14 @@ public class TrivialMain {
}
}</pre>
- <p>The contents of <em>test.html</em> should be similar to:
+ <p>The command</p>
+
+ <p class="source">java chapters.layouts.TrivialMain src/main/java/chapters/appenders/conf/logback-HtmlToConsole.xml</p>
+
+ <p>will create the file <em>test.html</em> in the current
+ folder. The contents of <em>test.html</em> should be similar to:
</p>
- <img src="images/htmlLayout1.jpg" alt="HTML Layout Sample Image"/>
+ <img src="images/chapters/layouts/htmlLayout1.jpg" alt="HTML Layout Sample Image"/>
<h3>Stack traces</h3>
@@ -1737,27 +1786,30 @@ public class TrivialMain {
</p>
<pre class="prettyprint source"><configuration>
- <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
- <ActiveFileName>lastLogEntries.html</ActiveFileName>
- <FileNamePattern>logEntries.%d{yyyy-MM-dd}.log</FileNamePattern>
- </rollingPolicy>
-
- <layout class="ch.qos.logback.classic.html.HTMLLayout">
- <cssBuilder class="ch.qos.logback.core.html.UrlCssBuilder">
- <url>address_of_a_custom_stylesheet.css</url>
- </cssBuilder>
- <Pattern>%relative%thread%mdc%level%logger%msg</Pattern>
- <b><Title>Logging Events</Title></b>
- </layout>
- </appender>
+ <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>lastLogEntries.html</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>logEntries.%d{yyyy-MM-dd}.log</fileNamePattern>
+ </rollingPolicy>
- <root level="debug">
- <appender-ref ref="FILE" />
- </root>
+ <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <cssBuilder class="ch.qos.logback.core.html.UrlCssBuilder">
+ <url>address_of_a_custom_stylesheet.css</url>
+ </cssBuilder>
+ <pattern>%relative%thread%mdc%level%logger%msg</pattern>
+ <b><title>Logging Events</title></b>
+ </layout>
+ </encoder>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="FILE" />
+ </root>
</configuration></pre>
- <h3><a name="log4jXMLLayout" href="#log4jXMLLayout">Log4j XMLLayout</a></h3>
+ <h2><a name="log4jXMLLayout" href="#log4jXMLLayout">Log4j
+ XMLLayout</a></h2>
<p><a
@@ -1775,11 +1827,11 @@ public class TrivialMain {
<p>As the original XMLLayout in log4j version 1.2.15, XMLLayout in
logback-classic admits two boolean properties, <span
- class="option">LocationInfo</span> and <span
- class="option">Properties</span>. Setting <span
- class="option">LocationInfo</span> to true enables the inclusion
+ class="option">locationInfo</span> and <span
+ class="option">properties</span>. Setting <span
+ class="option">locationInfo</span> to true enables the inclusion
of location info (caller data) in the each event. Setting <span
- class="option">Properties</span> to true enables the inclusion of
+ class="option">properties</span> to true enables the inclusion of
MDC information. Both options are set to false by default.
</p>
@@ -1787,13 +1839,15 @@ public class TrivialMain {
<pre class="prettyprint source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
- <File>test.xml</File>
- <layout class="ch.qos.logback.classic.log4j.XMLLayout">
- <LocationInfo>true</LocationInfo>
- </layout>
+ <file>test.xml</file>
+ <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
+ <layout class="ch.qos.logback.classic.log4j.XMLLayout">
+ <locationInfo>true</locationInfo>
+ </layout>
+ </encoder>
</appender>
- <root level="debug">
+ <root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration> </pre>
@@ -2110,7 +2164,7 @@ public class TrivialMain {
<p>Here is a sample output produced by <code>HTMLLayout</code> in
logback-access:</p>
- <img src="images/htmlLayoutAccess.gif" alt="Access HTML Layout Sample Image"/>
+ <img src="images/chapters/layouts/htmlLayoutAccess.gif" alt="Access HTML Layout Sample Image"/>
<p>What can be better than a real world example? Our own log4j
properties for logback <a
diff --git a/logback-site/src/site/resources/manual/images/htmlLayout0.gif b/logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayout0.gif
similarity index 100%
rename from logback-site/src/site/resources/manual/images/htmlLayout0.gif
rename to logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayout0.gif
diff --git a/logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayout1.png b/logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayout1.png
new file mode 100644
index 0000000..8969743
Binary files /dev/null and b/logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayout1.png differ
diff --git a/logback-site/src/site/resources/manual/images/htmlLayoutAccess.gif b/logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayoutAccess.gif
similarity index 100%
rename from logback-site/src/site/resources/manual/images/htmlLayoutAccess.gif
rename to logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayoutAccess.gif
diff --git a/logback-site/src/site/resources/manual/images/htmlLayout1.jpg b/logback-site/src/site/resources/manual/images/htmlLayout1.jpg
deleted file mode 100644
index 4bec059..0000000
Binary files a/logback-site/src/site/resources/manual/images/htmlLayout1.jpg and /dev/null differ
-----------------------------------------------------------------------
Summary of changes:
.../classic/turbo/ReconfigureOnChangeTest.java | 6 +-
.../core/encoder/LayoutWrappingEncoder.java | 2 +-
.../appenders/conf/logback-HtmlToConsole.xml | 14 +-
.../java/chapters/filters/levelFilterConfig.xml | 4 +-
.../java/chapters/filters/sampleFilterConfig.xml | 9 +-
.../chapters/filters/thresholdFilterConfig.xml | 4 +-
.../layouts/ExceptionEvaluatorExample.java | 8 +-
.../main/java/chapters/layouts/SampleLogging.java | 14 +-
...allerEvaluatorExample.java => TrivialMain.java} | 38 ++--
.../chapters/layouts/exceptionEvaluatorConfig.xml | 10 +-
.../java/chapters/layouts/htmlLayoutConfig1.xml | 14 +
.../chapters/layouts/mySampleConverterConfig.xml | 14 +-
logback-site/src/site/pages/manual/filters.html | 77 +++---
logback-site/src/site/pages/manual/layouts.html | 258 ++++++++++++--------
.../images/{ => chapters/layouts}/htmlLayout0.gif | Bin 9841 -> 9841 bytes
.../manual/images/chapters/layouts/htmlLayout1.png | Bin 0 -> 21825 bytes
.../{ => chapters/layouts}/htmlLayoutAccess.gif | Bin 148822 -> 148822 bytes
.../site/resources/manual/images/htmlLayout1.jpg | Bin 37074 -> 0 bytes
18 files changed, 271 insertions(+), 201 deletions(-)
copy logback-examples/src/main/java/chapters/layouts/{CallerEvaluatorExample.java => TrivialMain.java} (57%)
create mode 100644 logback-examples/src/main/java/chapters/layouts/htmlLayoutConfig1.xml
rename logback-site/src/site/resources/manual/images/{ => chapters/layouts}/htmlLayout0.gif (100%)
create mode 100644 logback-site/src/site/resources/manual/images/chapters/layouts/htmlLayout1.png
rename logback-site/src/site/resources/manual/images/{ => chapters/layouts}/htmlLayoutAccess.gif (100%)
delete mode 100644 logback-site/src/site/resources/manual/images/htmlLayout1.jpg
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list