
Author: seb Date: Fri Jan 5 15:23:44 2007 New Revision: 1164 Added: logback/trunk/logback-examples/src/main/java/chapter6/levelFilterConfig.xml Modified: logback/trunk/logback-examples/src/main/java/chapter3/variables2.properties logback/trunk/logback-site/src/site/xdocTemplates/manual/filters.xml logback/trunk/logback-site/src/site/xdocTemplates/manual/joran.xml Log: Added an example for LevelFilter Corrected variable naming not to conflict with existing variable names Example enumeration corrected Modified: logback/trunk/logback-examples/src/main/java/chapter3/variables2.properties ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter3/variables2.properties (original) +++ logback/trunk/logback-examples/src/main/java/chapter3/variables2.properties Fri Jan 5 15:23:44 2007 @@ -1,3 +1,3 @@ user.home.dir=/Users/seb -file=myApp.log -destination=${user.home.dir}/${file} \ No newline at end of file +fileName=myApp.log +destination=${user.home.dir}/${fileName} \ No newline at end of file Added: logback/trunk/logback-examples/src/main/java/chapter6/levelFilterConfig.xml ============================================================================== --- (empty file) +++ logback/trunk/logback-examples/src/main/java/chapter6/levelFilterConfig.xml Fri Jan 5 15:23:44 2007 @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<configuration> + <appender name="CONSOLE" + class="ch.qos.logback.core.ConsoleAppender"> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>INFO</level> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern> + %-4relative [%thread] %-5level %logger{30} - %msg%n + </pattern> + </layout> + </appender> + <root> + <level value="DEBUG" /> + <appender-ref ref="CONSOLE" /> + </root> +</configuration> \ No newline at end of file Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/filters.xml ============================================================================== --- logback/trunk/logback-site/src/site/xdocTemplates/manual/filters.xml (original) +++ logback/trunk/logback-site/src/site/xdocTemplates/manual/filters.xml Fri Jan 5 15:23:44 2007 @@ -121,7 +121,7 @@ neutral response to any logging event who's message does not contain this String. </p> -<em>Example 6.2: Basic custom filter (<a href="../xref/chapter6/SampleFilter.html">logback-examples/src/main/java/chapter6/SampleFilter.java</a>)</em> +<em>Example 6.1: Basic custom filter (<a href="../xref/chapter6/SampleFilter.html">logback-examples/src/main/java/chapter6/SampleFilter.java</a>)</em> <div class="source"><pre>package chapter6; import ch.qos.logback.classic.spi.LoggingEvent; @@ -148,7 +148,7 @@ shown below: </p> -<em>Example 6.3: SampleFilter configuration (logback-examples/src/main/java/chapter6/SampleFilterConfig.xml)</em> +<em>Example 6.2: SampleFilter configuration (logback-examples/src/main/java/chapter6/SampleFilterConfig.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> @@ -182,6 +182,40 @@ two attribute: <em>OnMatch</em> and <em>OnMismatch</em>, that can be configured like any other option. </p> + + <h3>Logback Filters</h3> + + <p> + As the moment, there is one filter that ships with + logback. This is the most commonly used filter: + <a href="../xref/ch/qos/logback/classic/LevelFilter.html"> + <code>LevelFilter</code></a>. + It provides event filtering based on a <code>Level</code> value. It the event's + level is equal or higher than the configured level, the filter accepts of denies + the event, depending on its configuration. Here is a sample configuration that + uses <code>LevelFilter</code>. + </p> + +<em>Example 6.3: SampleFilter configuration (logback-examples/src/main/java/chapter6/LevelFilterConfig.xml)</em> +<div class="source"><pre><configuration> + <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 class="ch.qos.logback.classic.PatternLayout"> + <pattern> + %-4relative [%thread] %-5level %logger{30} - %msg%n + </pattern> + </layout> + </appender> + <root> + <level value="DEBUG" /> + <appender-ref ref="CONSOLE" /> + </root> +</configuration></pre></div> <h3>Evaluator Filters</h3> @@ -215,7 +249,7 @@ Let's see a sample configuration. </p> -<em>Example 6.1: Basic event evaluator usage (logback-examples/src/main/java/chapter6/basicEventEvaluator.xml)</em> +<em>Example 6.4: Basic event evaluator usage (logback-examples/src/main/java/chapter6/basicEventEvaluator.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -250,7 +284,7 @@ </p> <p> - The implicit variables available to the <code>EventEvaluator</code> are descripbed below: + The implicit variables available to the <code>EventEvaluator</code> are described below: </p> <table> @@ -446,7 +480,7 @@ Here is a sample configuration that makes use of the newly created <code>TurboFilter</code>. </p> -<em>Example 6.5: Basic custom <code>TurboFilter</code> configuration (logback-examples/src/main/java/chapter6/sampleTurboFilterConfig.xml)</em> +<em>Example 6.6: Basic custom <code>TurboFilter</code> configuration (logback-examples/src/main/java/chapter6/sampleTurboFilterConfig.xml)</em> <div class="source"><pre><configuration> <b><turboFilter class="chapter6.SampleTurboFilter"> <Marker>sample</Marker> @@ -480,7 +514,7 @@ <code>MarkerFilter</code>. </p> -<em>Example 6.4: <code>MDCFilter</code> and <code>MarkerFilter</code> +<em>Example 6.7: <code>MDCFilter</code> and <code>MarkerFilter</code> configuration (logback-examples/src/main/java/chapter6/turboFilters.xml)</em> <div class="source"><pre><configuration> @@ -586,7 +620,7 @@ Here is a sample configuration that will ensure that any 404 error will be displayed: </p> -<em>Example 6.6: Access Evaluator (logback-examples/src/main/java/chapter6/accessEventEvaluator.xml)</em> +<em>Example 6.8: Access Evaluator (logback-examples/src/main/java/chapter6/accessEventEvaluator.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -614,7 +648,7 @@ would look like: </p> -<em>Example 6.7: Access Evaluator (logback-examples/src/main/java/chapter6/accessEventEvaluator2.xml)</em> +<em>Example 6.9: Access Evaluator (logback-examples/src/main/java/chapter6/accessEventEvaluator2.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/joran.xml ============================================================================== --- logback/trunk/logback-site/src/site/xdocTemplates/manual/joran.xml (original) +++ logback/trunk/logback-site/src/site/xdocTemplates/manual/joran.xml Fri Jan 5 15:23:44 2007 @@ -103,7 +103,7 @@ this is done with the help of an imaginary application called <code>MyApp1</code>. </p> -<em>Example 3.5: Simple example of <code>BasicConfigurator</code> usage +<em>Example 3.1: Simple example of <code>BasicConfigurator</code> usage <a href="../xref/chapter3/MyApp1.html">(logback-examples/src/main/java/chapter3/MyApp1.java)</a></em> <div class="source"><pre>package chapter3; @@ -176,7 +176,7 @@ be controlled at runtime. Here is a slightly modified version called <code>MyApp2</code>. </p> -<em>Example 3.6: Simple example of <code>BasicConfigurator</code> usage <a href="../xref/chapter3/MyApp2.html">(logback-examples/src/main/java/chapter3/MyApp2.java)</a></em> +<em>Example 3.2: Simple example of <code>BasicConfigurator</code> usage <a href="../xref/chapter3/MyApp2.html">(logback-examples/src/main/java/chapter3/MyApp2.java)</a></em> <div class="source"><pre>package chapter3; import org.slf4j.Logger; @@ -217,7 +217,7 @@ listed below: </p> -<em>Example 3.7: Basic configuration file (logback-examples/src/main/java/chapter3/sample0.xml)</em> +<em>Example 3.3: Basic configuration file (logback-examples/src/main/java/chapter3/sample0.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -257,7 +257,7 @@ configuration file, as shown above: </p> -<em>Example 3.8: Basic configuration file using debug mode (logback-examples/src/main/java/chapter3/sample1.xml)</em> +<em>Example 3.4: Basic configuration file using debug mode (logback-examples/src/main/java/chapter3/sample1.xml)</em> <div class="source"><pre><configuration debug="true"> <appender name="STDOUT" @@ -350,7 +350,7 @@ belonging to the chapter3 package. The following configuration file shows how to achieve that. </p> -<em>Example 3.8: Setting the level of a logger (logback-examples/src/main/java/chapter3/sample2.xml)</em> +<em>Example 3.5: Setting the level of a logger (logback-examples/src/main/java/chapter3/sample2.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -388,7 +388,7 @@ to <code>DEBUG</code>. </p> -<em>Example 3.8: Setting the level of multiple loggers (logback-examples/src/main/java/chapter3/sample3.xml)</em> +<em>Example 3.6: Setting the level of multiple loggers (logback-examples/src/main/java/chapter3/sample3.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -468,7 +468,7 @@ on the effective level of the logger being invoked, not the level of the logger where the appenders are attached. The configuration file <em>sample4.xml</em> is a case in point: </p> -<em>Example 3.9: Logger level sample (logback-examples/src/main/java/chapter3/sample4.xml)</em> +<em>Example 3.7: Logger level sample (logback-examples/src/main/java/chapter3/sample4.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -570,7 +570,7 @@ and referencing them in a logger, as the next configuration file illustrates: </p> -<em>Example 3.10: Multiple loggers (logback-examples/src/main/java/chapter3/multiple.xml)</em> +<em>Example 3.8: Multiple loggers (logback-examples/src/main/java/chapter3/multiple.xml)</em> <div class="source"><pre><configuration> <appender name="<b>FILE</b>" @@ -632,7 +632,7 @@ logging output to be duplicated. </p> -<em>Example 3.11: Duplicate appender (logback-examples/src/main/java/chapter3/duplicate.xml)</em> +<em>Example 3.9: Duplicate appender (logback-examples/src/main/java/chapter3/duplicate.xml)</em> <div class="source"><pre><configuration> <appender name="STDOUT" @@ -681,7 +681,7 @@ while messages only from some specific set of loggers flow into a specific appender. </p> -<em>Example 3.11: Multiple appender (logback-examples/src/main/java/chapter3/restricted.xml)</em> +<em>Example 3.10: Multiple appender (logback-examples/src/main/java/chapter3/restricted.xml)</em> <div class="source"><pre><configuration> <appender name="FILE" @@ -731,7 +731,7 @@ different than those of the rest of the tree. </p> -<em>Example 3.12: Additivity flag (logback-examples/src/main/java/chapter3/additivityFlag.xml)</em> +<em>Example 3.11: Additivity flag (logback-examples/src/main/java/chapter3/additivityFlag.xml)</em> <div class="source"><pre><configuration> <appender name="FILE" @@ -916,8 +916,8 @@ <em>Example 3.16: Recursive use of variables (logback-examples/src/main/java/chapter3/variables2.properties)</em> <div class="source"><pre>user.home.dir=/Users/seb -file=myApp.log -destination=${user.home.dir}/${file}</pre></div> +fileName=myApp.log +destination=${user.home.dir}/${fileName}</pre></div> <p> In the configuration file, only the last variable, <em>${destination}</em> will @@ -1188,7 +1188,7 @@ <p>The <em>calculator2.xml</em> file is a bit more complex, but much more interesting.</p> <p>It contains the following elements:</p> -<em>Example 3.1: Calculator configuration file (logback-examples/src/main/java/chapter3/calculator/calculator2.xml)</em> +<em>Example 3.18: Calculator configuration file (logback-examples/src/main/java/chapter3/calculator/calculator2.xml)</em> <div class="source"><pre><computation name="toto"> <literal value="7"/> <literal value="3"/> @@ -1214,7 +1214,7 @@ elements that contain instances of the same element. Here's the content of <em>calculator3.xml</em>:</p> -<em>Example 3.2: Calculator configuration file (logback-examples/src/main/java/chapter3/calculator/calculator3.xml)</em> +<em>Example 3.19: Calculator configuration file (logback-examples/src/main/java/chapter3/calculator/calculator3.xml)</em> <div class="source"><pre><computation name="toto"> <computation> <literal value="7"/> @@ -1262,7 +1262,7 @@ <p>Using new rule declarations, the preceding example, involving the calculation, could be expressed this way:</p> -<em>Example 3.3: Configuration file using new rules on the fly (logback-examples/src/main/java/chapter3/newrule/new-rule.xml)</em> +<em>Example 3.20: Configuration file using new rules on the fly (logback-examples/src/main/java/chapter3/newrule/new-rule.xml)</em> <div class="source"><pre><computation name="toto"> <new-rule pattern="*/computation/literal" actionClass="chapter3.calculator.LiteralAction"/> @@ -1362,7 +1362,7 @@ <p>The <em>implicit1.xml</em> file contains the following lines:</p> -<em>Example 3.4: Usage of implicit rules (logback-examples/src/main/java/chapter3/implicit/implicit1.xml)</em> +<em>Example 3.21: Usage of implicit rules (logback-examples/src/main/java/chapter3/implicit/implicit1.xml)</em> <div class="source"><pre><foo> <xyz printme="true">