logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
October 2006
- 6 participants
- 258 discussions
Author: seb
Date: Fri Oct 27 15:12:49 2006
New Revision: 802
Modified:
logback/trunk/logback-examples/ (props changed)
Log:
1
0

svn commit: r801 - in logback/trunk: logback-access logback-classic logback-core
by noreply.seb@qos.ch 27 Oct '06
by noreply.seb@qos.ch 27 Oct '06
27 Oct '06
Author: seb
Date: Fri Oct 27 15:12:07 2006
New Revision: 801
Modified:
logback/trunk/logback-access/pom.xml
logback/trunk/logback-classic/pom.xml
logback/trunk/logback-core/pom.xml
Log:
minor fix
Modified: logback/trunk/logback-access/pom.xml
==============================================================================
--- logback/trunk/logback-access/pom.xml (original)
+++ logback/trunk/logback-access/pom.xml Fri Oct 27 15:12:07 2006
@@ -14,7 +14,7 @@
<packaging>jar</packaging>
<name>Logback Access Module</name>
- <url>http://logback.qos.ch/access</url>
+ <url>http://logback.qos.ch</url>
<description>
<!--
Never _never_ let Eclipse's auto format function add
Modified: logback/trunk/logback-classic/pom.xml
==============================================================================
--- logback/trunk/logback-classic/pom.xml (original)
+++ logback/trunk/logback-classic/pom.xml Fri Oct 27 15:12:07 2006
@@ -14,7 +14,7 @@
<packaging>jar</packaging>
<name>Logback Classic Module</name>
- <url>http://logback.qos.ch/classic</url>
+ <url>http://logback.qos.ch</url>
<description>
<!--
Never _never_ let Eclipse's auto format function add
Modified: logback/trunk/logback-core/pom.xml
==============================================================================
--- logback/trunk/logback-core/pom.xml (original)
+++ logback/trunk/logback-core/pom.xml Fri Oct 27 15:12:07 2006
@@ -14,7 +14,7 @@
<packaging>jar</packaging>
<name>Logback Core Module</name>
- <url>http://logback.qos.ch/core</url>
+ <url>http://logback.qos.ch</url>
<description>
<!--
Never _never_ let Eclipse's auto format function add
1
0
Author: seb
Date: Fri Oct 27 15:11:46 2006
New Revision: 800
Modified:
logback/trunk/logback-examples/ (props changed)
Log:
1
0
Author: seb
Date: Fri Oct 27 14:53:15 2006
New Revision: 799
Added:
logback/trunk/logback-examples/
logback/trunk/logback-examples/pom.xml
logback/trunk/logback-examples/src/
logback/trunk/logback-examples/src/main/
logback/trunk/logback-examples/src/main/java/
logback/trunk/logback-examples/src/main/java/chapter1/
logback/trunk/logback-examples/src/main/java/chapter1/Bar.java
logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java
logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java
logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java
logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java
logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java
logback/trunk/logback-examples/src/main/java/chapter1/sample-config-1.xml
logback/trunk/logback-examples/src/main/java/chapter1/sample-config-2.xml
logback/trunk/logback-examples/src/main/java/chapter1/sample-config-3.xml
logback/trunk/logback-examples/src/main/java/chapter4/
logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java
logback/trunk/logback-examples/src/main/java/chapter4/conf/
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-Console.xml
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-HtmlToConsole.xml
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-MDC.xml
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-RollingSizeBased.xml
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-RollingTimeBased.xml
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-SMTP.xml
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-SMTPWithHtml.xml
logback/trunk/logback-examples/src/main/java/chapter4/sub/
logback/trunk/logback-examples/src/main/java/chapter4/sub/sample/
logback/trunk/logback-examples/src/main/java/chapter4/sub/sample/Bar.java
logback/trunk/logback-examples/src/main/java/chapter5/
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/MySampleConverter.java
logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout.java
logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout2.java
logback/trunk/logback-examples/src/main/java/chapter5/PatternSample.java
logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java
logback/trunk/logback-examples/src/main/java/chapter5/TestException.java
logback/trunk/logback-examples/src/main/java/chapter5/callerEvaluatorConfig.xml
logback/trunk/logback-examples/src/main/java/chapter5/exceptionEvaluatorConfig.xml
logback/trunk/logback-examples/src/main/java/chapter5/mdcfilter.xml
logback/trunk/logback-examples/src/main/java/chapter5/mySampleConverterConfig.xml
logback/trunk/logback-examples/src/main/java/chapter5/sampleLayoutConfig.xml
logback/trunk/logback-examples/src/main/java/chapter5/sampleLayoutConfig2.xml
logback/trunk/logback-examples/src/main/java/joran/
logback/trunk/logback-examples/src/main/java/joran/SimpleConfigurator.java
logback/trunk/logback-examples/src/main/java/joran/calculator/
logback/trunk/logback-examples/src/main/java/joran/calculator/AddAction.java
logback/trunk/logback-examples/src/main/java/joran/calculator/Calculator1.java
logback/trunk/logback-examples/src/main/java/joran/calculator/Calculator2.java
logback/trunk/logback-examples/src/main/java/joran/calculator/ComputationAction1.java
logback/trunk/logback-examples/src/main/java/joran/calculator/ComputationAction2.java
logback/trunk/logback-examples/src/main/java/joran/calculator/LiteralAction.java
logback/trunk/logback-examples/src/main/java/joran/calculator/MultiplyAction.java
logback/trunk/logback-examples/src/main/java/joran/calculator/calculator1.xml
logback/trunk/logback-examples/src/main/java/joran/calculator/calculator2.xml
logback/trunk/logback-examples/src/main/java/joran/calculator/calculator3.xml
logback/trunk/logback-examples/src/main/java/joran/calculator/readme.txt
logback/trunk/logback-examples/src/main/java/joran/helloWorld/
logback/trunk/logback-examples/src/main/java/joran/helloWorld/HelloWorld.java
logback/trunk/logback-examples/src/main/java/joran/helloWorld/HelloWorldAction.java
logback/trunk/logback-examples/src/main/java/joran/helloWorld/hello.xml
logback/trunk/logback-examples/src/main/java/joran/helloWorld/readme.txt
logback/trunk/logback-examples/src/main/java/joran/implicit/
logback/trunk/logback-examples/src/main/java/joran/implicit/NOPAction.java
logback/trunk/logback-examples/src/main/java/joran/implicit/PrintMe.java
logback/trunk/logback-examples/src/main/java/joran/implicit/PrintMeImplicitAction.java
logback/trunk/logback-examples/src/main/java/joran/implicit/implicit1.xml
logback/trunk/logback-examples/src/main/java/joran/implicit/readme.txt
logback/trunk/logback-examples/src/main/java/joran/newRule/
logback/trunk/logback-examples/src/main/java/joran/newRule/NewRuleCalculator.java
logback/trunk/logback-examples/src/main/java/joran/newRule/new-rule.xml
logback/trunk/logback-examples/src/main/java/joran/newRule/readme.txt
Modified:
logback/trunk/pom.xml
logback/trunk/src/main/assembly/dist.xml
Log:
added logback-example module
Added: logback/trunk/logback-examples/pom.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/pom.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,61 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback</artifactId>
+ <version>0.6-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-examples</artifactId>
+ <version>0.6-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Logback Examples Module</name>
+
+ <url>http://logback.qos.ch</url>
+ <description>
+ <!--
+ Never _never_ let Eclipse's auto format function add
+ a line return in the description.
+ The generated jar will contain a corrupt MANIFEST file.
+ -->
+ Logback: the generic, reliable, fast and flexible logging library for Java.
+ </description>
+ <licenses>
+ <license>
+ <name> GNU Lesser General Public License</name>
+ <url>http://www.gnu.org/licenses/lgpl.html</url>
+ </license>
+ </licenses>
+
+ <dependencies>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-access</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter1/Bar.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/Bar.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,11 @@
+package chapter1;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class Bar {
+ Logger logger = LoggerFactory.getLogger(Bar.class);
+ public void doIt() {
+ logger.debug("doing my job");
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,13 @@
+package chapter1;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HelloWorld1 {
+
+ public static void main(String[] args) {
+
+ Logger logger = LoggerFactory.getLogger("chapter1.HelloWorld1");
+ logger.debug("Hello world.");
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,15 @@
+package chapter1;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.util.LoggerStatusPrinter;
+
+public class HelloWorld2 {
+
+ public static void main(String[] args) {
+ Logger logger = LoggerFactory.getLogger("chapter1.HelloWorld2");
+ logger.debug("Hello world.");
+ LoggerStatusPrinter.printStatusInDefaultContext();
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,18 @@
+package chapter1;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.BasicConfigurator;
+import ch.qos.logback.classic.util.LoggerStatusPrinter;
+
+public class HelloWorld3 {
+
+ public static void main(String[] args) {
+ Logger logger = LoggerFactory.getLogger("chapter1.HelloWorld3");
+
+ BasicConfigurator.configureDefaultContext();
+ logger.debug("Hello world.");
+ LoggerStatusPrinter.printStatusInDefaultContext();
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,22 @@
+package chapter1;
+
+// Import SLF4J classes.
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.BasicConfigurator;
+
+public class MyApp {
+
+ public static void main(String[] args) {
+ // Set up a simple configuration that logs on the console.
+ BasicConfigurator.configureDefaultContext();
+
+ Logger logger = LoggerFactory.getLogger(MyApp.class);
+
+ logger.info("Entering application.");
+ Bar bar = new Bar();
+ bar.doIt();
+ logger.info("Exiting application.");
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,31 @@
+package chapter1;
+
+//Import SLF4J classes.
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class MyAppWithConfigFile {
+
+ public static void main(String[] args) {
+ Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc.getStatusManager());
+ }
+ logger.info("Entering application.");
+ Bar bar = new Bar();
+ bar.doIt();
+ logger.info("Exiting application.");
+
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter1/sample-config-1.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/sample-config-1.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
Added: logback/trunk/logback-examples/src/main/java/chapter1/sample-config-2.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/sample-config-2.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ </appender>
+
+ <appender name="FILE"
+ class="ch.qos.logback.core.FileAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ <param name="File"
+ value="sample-log.txt" />
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
Added: logback/trunk/logback-examples/src/main/java/chapter1/sample-config-3.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter1/sample-config-3.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ </appender>
+
+ <appender name="FILE"
+ class="ch.qos.logback.core.FileAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ <param name="File"
+ value="sample-log.txt" />
+ </appender>
+
+ <logger name="chapter1">
+ <level value="info" />
+ </logger>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
Added: logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ConfigurationTester.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,50 @@
+package chapter4;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.MDC;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+import chapter4.sub.sample.Bar;
+
+/**
+ *
+ * This class can be used to check the result of a configuration file.
+ * <p>
+ * When all the logback-core, logback-classic and their dependencies have been
+ * added to the ClassPath, one can launch this class using the following
+ * command:
+ * <p>
+ * java chapter4.ConfigurationTester
+ * chapter4/conf/name_of_the_configuration_file.xml
+ *
+ * @author Sébastien Pennec
+ */
+public class ConfigurationTester {
+
+ public static void main(String[] args) throws InterruptedException {
+ Logger logger = (Logger) LoggerFactory.getLogger(ConfigurationTester.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ je.printStackTrace();
+ }
+ logger.debug("**Hello {}", new Bar());
+ MDC.put("testKey", "testValueFromMDC");
+ MDC.put("testKey2", "value2");
+ for (int i = 0; i < 10; i++) {
+ logger.debug("logging statement " + i);
+ }
+ Bar bar = new Bar();
+ bar.createLoggingRequest();
+
+ StatusPrinter.print(lc.getStatusManager());
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-Console.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-Console.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,16 @@
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level - %msg %n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-HtmlToConsole.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-HtmlToConsole.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,19 @@
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <cssBuilder class="ch.qos.logback.core.helpers.CssBuilder">
+ <param name="url" value="path_to_StyleFile.css" />
+ </cssBuilder>
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level - %msg%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-MDC.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-MDC.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,16 @@
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level %X{testKey} - %msg%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-RollingSizeBased.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-RollingSizeBased.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,30 @@
+<configuration>
+
+ <appender name="FILE"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <rollingPolicy
+ class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <param name="ActiveFileName" value="testFile.log" />
+ <param name="FileNamePattern" value="testFile.%i.log" />
+ <param name="MinIndex" value="1" />
+ <param name="MaxIndex" value="3" />
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <param name="MaxFileSize" value="5MB" />
+ </triggeringPolicy>
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ </appender>
+
+
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-RollingTimeBased.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-RollingTimeBased.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,17 @@
+<configuration>
+ <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <param name="ActiveFileName" value="outputFile.log" />
+ <param name="FileNamePattern" value="logFile.%d{yyyy-MM-dd}.log" />
+ </rollingPolicy>
+
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern" value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-SMTP.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-SMTP.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,22 @@
+<configuration>
+
+ <appender name="SMTP"
+ class="ch.qos.logback.classic.net.SMTPAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="pattern"
+ value="%-4relative [%thread] %-5level %class - %msg%n" />
+ </layout>
+ <param name="From" value="test.nospam(a)qos.ch" />
+ <param name="SMTPHost" value="mail.qos.ch" />
+
+ <param name="Subject" value="Last Event: %-10logger %nopex" />
+
+ <param name="To" value="sebastien(a)qos.ch" />
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="SMTP" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-SMTPWithHtml.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-SMTPWithHtml.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,21 @@
+<configuration>
+
+ <appender name="SMTP"
+ class="ch.qos.logback.classic.net.SMTPAppender">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <param name="pattern" value="%relative%thread%mdc%level%class%msg" />
+ <throwableRenderer class="ch.qos.logback.classic.html.DefaultThrowableRenderer" />
+ </layout>
+ <param name="From" value="test.nospam(a)qos.ch" />
+ <param name="SMTPHost" value="mail.qos.ch" />
+ <param name="Subject" value="LastEvent: %class - %msg %nopex" />
+
+ <param name="To" value="sebastien(a)qos.ch" />
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="SMTP" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/sub/sample/Bar.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/sub/sample/Bar.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,21 @@
+package chapter4.sub.sample;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Bar {
+ Logger logger = LoggerFactory.getLogger(Bar.class);
+
+ public String toString() {
+ return "test 123";
+ }
+
+ public void createLoggingRequest() {
+ subMethodToCreateRequest();
+ }
+
+ //this is done to create a stacktrace of more than one line
+ private void subMethodToCreateRequest() {
+ logger.error("error-level request", new Exception("test exception"));
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/CallerEvaluatorExample.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,34 @@
+package chapter5;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class CallerEvaluatorExample {
+
+ public static void main(String[] args) {
+ Logger logger = (Logger) LoggerFactory
+ .getLogger(CallerEvaluatorExample.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
+
+ for (int i = 0; i < 5; i++) {
+ if (i == 3) {
+ logger.debug("who calls thee?");
+ } else {
+ logger.debug("I know me " + i);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/ExceptionEvaluatorExample.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,36 @@
+package chapter5;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+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 = (Logger) LoggerFactory
+ .getLogger(ExceptionEvaluatorExample.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
+ for (int i = 0; i < 5; i++) {
+ if (i == 3) {
+ logger.debug("logging statement " + i, new TestException(
+ "do not display this"));
+ } else {
+ logger.debug("logging statement " + i, new Exception("display"));
+ }
+ }
+
+ StatusPrinter.print(lc);
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/GoMDC.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/GoMDC.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,34 @@
+package chapter5;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.MDC;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class GoMDC {
+
+ public static void main(String[] args) {
+ Logger logger = (Logger) LoggerFactory
+ .getLogger(GoMDC.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure("mdcFilter.xml");
+
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
+
+ logger.debug("I know me " + 0);
+ MDC.put("key", "val");
+ logger.debug("I know me " + 1);
+
+ StatusPrinter.print(lc);
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/MySampleConverter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/MySampleConverter.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,38 @@
+package chapter5;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.pattern.ClassicConverter;
+import ch.qos.logback.classic.spi.LoggingEvent;
+
+public class MySampleConverter extends ClassicConverter {
+
+ private static final String END_COLOR = "\u001b[m";
+
+ private static final String ERROR_COLOR = "\u001b[0;31m";
+ private static final String WARN_COLOR = "\u001b[0;33m";
+
+ @Override
+ public String convert(Object eventObject) {
+ LoggingEvent event = (LoggingEvent) eventObject;
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append(getColor(event.getLevel()));
+ sbuf.append(event.getLevel());
+ sbuf.append(END_COLOR);
+ return sbuf.toString();
+ }
+
+ /**
+ * Returns the appropriate characters to change the color for the specified
+ * logging level.
+ */
+ private String getColor(Level level) {
+ switch (level.toInt()) {
+ case Level.ERROR_INT:
+ return ERROR_COLOR;
+ case Level.WARN_INT:
+ return WARN_COLOR;
+ default:
+ return "";
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,27 @@
+package chapter5;
+
+import ch.qos.logback.classic.ClassicLayout;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.LayoutBase;
+
+public class MySampleLayout extends LayoutBase implements ClassicLayout {
+
+ public String doLayout(LoggingEvent event) {
+ StringBuffer sbuf = new StringBuffer(128);
+ sbuf.append(event.getTimeStamp() - LoggingEvent.getStartTime());
+ sbuf.append(" ");
+ sbuf.append(event.getLevel());
+ sbuf.append(" [");
+ sbuf.append(event.getThreadName());
+ sbuf.append("] ");
+ sbuf.append(event.getLoggerRemoteView().getName());
+ sbuf.append(" - ");
+ sbuf.append(event.getFormattedMessage());
+ sbuf.append(LINE_SEP);
+ return sbuf.toString();
+ }
+
+ public String doLayout(Object event) {
+ return doLayout((LoggingEvent)event);
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout2.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,45 @@
+package chapter5;
+
+import ch.qos.logback.classic.ClassicLayout;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.LayoutBase;
+
+public class MySampleLayout2 extends LayoutBase implements ClassicLayout {
+
+ String prefix = null;
+ boolean printThreadName = true;
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public void setPrintThreadName(boolean printThreadName) {
+ this.printThreadName = printThreadName;
+ }
+
+ public String doLayout(LoggingEvent event) {
+ StringBuffer sbuf = new StringBuffer(128);
+ if (prefix != null) {
+ sbuf.append(prefix + ": ");
+ }
+ sbuf.append(event.getTimeStamp() - LoggingEvent.getStartTime());
+ sbuf.append(" ");
+ sbuf.append(event.getLevel());
+ if (printThreadName) {
+ sbuf.append(" [");
+ sbuf.append(event.getThreadName());
+ sbuf.append("] ");
+ } else {
+ sbuf.append(" ");
+ }
+ sbuf.append(event.getLoggerRemoteView().getName());
+ sbuf.append(" - ");
+ sbuf.append(event.getFormattedMessage());
+ sbuf.append(LINE_SEP);
+ return sbuf.toString();
+ }
+
+ public String doLayout(Object event) {
+ return doLayout((LoggingEvent) event);
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/PatternSample.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/PatternSample.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,28 @@
+package chapter5;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.core.ConsoleAppender;
+
+public class PatternSample {
+
+ static public void main(String[] args) throws Exception {
+ Logger rootLogger = (Logger) LoggerFactory.getLogger("root");
+
+ PatternLayout layout = new PatternLayout();
+ layout.setPattern("%-5level [%thread]: %message%n");
+ layout.start();
+
+ ConsoleAppender appender = new ConsoleAppender();
+ appender.setContext(rootLogger.getLoggerContext());
+ appender.setLayout(layout);
+ appender.start();
+
+ rootLogger.addAppender(appender);
+
+ rootLogger.debug("Message 1");
+ rootLogger.warn("Message 2");
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/SampleLogging.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,31 @@
+package chapter5;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class SampleLogging {
+
+ public static void main(String[] args) {
+ Logger logger = (Logger) LoggerFactory
+ .getLogger(SampleLogging.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
+
+ logger.debug("Everything's going well");
+
+ logger.error("... not quite");
+ }
+
+}
Added: logback/trunk/logback-examples/src/main/java/chapter5/TestException.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/TestException.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,10 @@
+package chapter5;
+
+public class TestException extends Exception {
+
+ private static final long serialVersionUID = 8326547927308399902L;
+
+ public TestException(String message) {
+ super(message);
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter5/callerEvaluatorConfig.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/callerEvaluatorConfig.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,19 @@
+<configuration>
+
+ <evaluator name="DISPLAY_CALLER_EVAL">
+ <Expression>logger.getName().contains("chapter5") && message.contains("who calls thee")</Expression>
+ </evaluator>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level - %msg%n %caller{2, DISPLAY_CALLER_EVAL}" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/exceptionEvaluatorConfig.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/exceptionEvaluatorConfig.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,19 @@
+<configuration>
+
+ <evaluator name="DISPLAY_EX_EVAL">
+ <Expression>throwable != null && throwable instanceof chapter5.TestException</Expression>
+ </evaluator>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level - %msg %ex{full, DISPLAY_EX_EVAL}%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/mdcfilter.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/mdcfilter.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,25 @@
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %-5level %X{testKey} - %msg%n" />
+ </layout>
+
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <Name>myFilter</Name>
+ <OnMatch>DENY</OnMatch>
+ <Evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
+ <Name>mdcEvaluator</Name>
+ <Expression>mdc!=null && "val".equals(mdc.get("key"))</Expression>
+ </Evaluator>
+ </filter>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
+
Added: logback/trunk/logback-examples/src/main/java/chapter5/mySampleConverterConfig.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/mySampleConverterConfig.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,17 @@
+<configuration>
+
+ <conversionRule conversionWord="sample" converterClass="chapter5.MySampleConverter" />
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <param name="Pattern"
+ value="%-4relative [%thread] %sample - %msg%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/sampleLayoutConfig.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/sampleLayoutConfig.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,12 @@
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="chapter5.MySampleLayout" />
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter5/sampleLayoutConfig2.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter5/sampleLayoutConfig2.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,15 @@
+<configuration>
+
+ <appender name="STDOUT"
+ class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="chapter5.MySampleLayout2">
+ <prefix>MyPrefix</prefix>
+ <printThreadName>false</printThreadName>
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/joran/SimpleConfigurator.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/SimpleConfigurator.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,55 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, 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 joran;
+
+import java.util.List;
+import java.util.Map;
+
+import ch.qos.logback.core.joran.GenericConfigurator;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.action.ImplicitAction;
+import ch.qos.logback.core.joran.spi.Interpreter;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.joran.spi.RuleStore;
+
+public class SimpleConfigurator extends GenericConfigurator {
+
+ final Map<Pattern, Action> ruleMap;
+ final List<ImplicitAction> iaList;
+
+ public SimpleConfigurator(Map<Pattern, Action> ruleMap) {
+ this(ruleMap, null);
+ }
+
+ public SimpleConfigurator(Map<Pattern, Action> ruleMap, List<ImplicitAction> iaList) {
+ this.ruleMap = ruleMap;
+ this.iaList = iaList;
+ }
+
+ @Override
+ protected void addInstanceRules(RuleStore rs) {
+
+ for (Pattern pattern : ruleMap.keySet()) {
+ Action action = ruleMap.get(pattern);
+ rs.addRule(pattern, action);
+ }
+ }
+
+ @Override
+ protected void addImplicitRules(Interpreter interpreter) {
+ if(iaList == null) {
+ return;
+ }
+ for (ImplicitAction ia : iaList) {
+ interpreter.addImplicitAction(ia);
+ }
+ }
+
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/AddAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/AddAction.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,71 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+
+import java.util.EmptyStackException;
+
+
+/**
+ * This action adds the two integers at the top of the stack (they are removed)
+ * and pushes the result to the top the stack.
+ *
+ * @author Ceki Gülcü
+ */
+public class AddAction extends Action {
+
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ int first = fetchInteger(ec);
+ int second = fetchInteger(ec);
+ // Push the result of the addition for the following actions.
+ ec.pushObject(new Integer(first + second));
+ }
+
+ /**
+ * Pop the Integer object at the top of the stack.
+ * This code illustrates usage of Joran's error handling paradigm.
+ */
+ int fetchInteger(InterpretationContext ec) {
+ int result = 0;
+
+ try {
+ // Pop the object at the top of the exection context stack.
+ Object o1 = ec.popObject();
+
+ if (o1 instanceof Integer) {
+ result = ((Integer) o1).intValue();
+ } else {
+ String errMsg =
+ "Object [" + o1
+ + "] currently at the top of the stack is not an integer.";
+ ec.addError(errMsg);
+ throw new IllegalArgumentException(errMsg);
+ }
+ } catch (EmptyStackException ese) {
+ ec.addError(("Expecting an integer on the execution stack."));
+ throw ese;
+ }
+ return result;
+ }
+
+ public void end(InterpretationContext ec, String name) {
+ // Nothing to do here.
+ // In general, the end() method of actions associated with elements
+ // having no children do not need to perform any processing in their
+ // end() method.
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/Calculator1.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/Calculator1.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,68 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import joran.SimpleConfigurator;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.util.StatusPrinter;
+
+/**
+ * This examples illustrates collaboration between multiple actions through the
+ * common execution context stack.
+ *
+ * The first and only argument of this application must be the path to the XML
+ * file to interpret. There are sample XML files in the
+ * <em>examples/src/joran/calculator/</em> directory.
+ *
+ * For example,
+ *
+ * <pre>
+ * java joran.calculator.Calculator1 examples/src/joran/calculator/calculator1.xml
+ * </pre>
+ *
+ * Please refer to the comments in the source code for more information.
+ *
+ * @author Ceki Güulcü
+ */
+public class Calculator1 {
+
+ public static void main(String[] args) throws Exception {
+ Context context = new ContextBase();
+
+ Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>();
+
+ // Associate "/computation" pattern with ComputationAction1
+ ruleMap.put(new Pattern("/computation"), new ComputationAction1());
+
+ // Other associations
+ ruleMap.put(new Pattern("/computation/literal"), new LiteralAction());
+ ruleMap.put(new Pattern("/computation/add"), new AddAction());
+ ruleMap.put(new Pattern("/computation/multiply"), new MultiplyAction());
+
+ SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
+ // link the configurator with its context
+ simpleConfigurator.setContext(context);
+
+ try {
+ simpleConfigurator.doConfigure(args[0]);
+ } catch (JoranException e) {
+ // Print any errors that might have occured.
+ StatusPrinter.print(context);
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/Calculator2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/Calculator2.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,60 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import joran.SimpleConfigurator;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.util.StatusPrinter;
+
+
+/**
+ * This examples illustrates collaboration between multiple actions through the
+ * common execution context stack.
+ *
+ * It differs from Calculator1 in that it supports arbitrary nesting of
+ * computation elements.
+ *
+ * You can test this application with the sample XML file <em>calculator3.xml</em>.
+ *
+ * @author Ceki Güulcü
+ */
+public class Calculator2 {
+ public static void main(String[] args) throws Exception {
+ Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>();
+
+
+ // Note the wild card character '*', in the paterns, signifying any level
+ // of nesting.
+ ruleMap.put(new Pattern("*/computation"), new ComputationAction2());
+
+ ruleMap.put(new Pattern("*/computation/literal"), new LiteralAction());
+ ruleMap.put(new Pattern("*/computation/add"), new AddAction());
+ ruleMap.put(new Pattern("*/computation/multiply"), new MultiplyAction());
+
+ Context context = new ContextBase();
+ SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
+ // link the configurator with its context
+ simpleConfigurator.setContext(context);
+
+ try {
+ simpleConfigurator.doConfigure(args[0]);
+ } catch (JoranException e) {
+ // Print any errors that might have occured.
+ StatusPrinter.print(context);
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/ComputationAction1.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/ComputationAction1.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,58 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.util.OptionHelper;
+
+
+/**
+ * ComputationAction1 will print the result of the compuration made by
+ * children elements but only if the compuration itself is named, that is if the
+ * name attribute of the associated computation element is not null. In other
+ * words, anonymous computations will not print their result.
+ *
+ * @author Ceki Gülcü
+ */
+public class ComputationAction1 extends Action {
+ public static String NAME_ATR = "name";
+
+ String nameStr;
+
+ /**
+ * Store the value of the name attribute for future use.
+ */
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ nameStr = attributes.getValue(NAME_ATR);
+ }
+
+ /**
+ * Children elements have been processed. The sesults should be an integer
+ * placed at the top of the execution stack.
+ *
+ * This value will be printed on the console but only if the action is
+ * named. Anonymous computation will not print their result.
+ */
+ public void end(InterpretationContext ec, String name) {
+ if (OptionHelper.isEmpty(nameStr)) {
+ // nothing to do
+ } else {
+ Integer i = (Integer) ec.peekObject();
+ System.out.println(
+ "The computation named [" + nameStr + "] resulted in the value " + i);
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/ComputationAction2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/ComputationAction2.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,83 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.util.OptionHelper;
+
+
+/**
+ * ComputationAction2 will print the result of the compuration made by
+ * children elements but only if the compuration itself is named, that is if the
+ * name attribute of the associated computation element is not null. In other
+ * words, anonymous computations will not print their result.
+ *
+ * ComputationAction2 differs from ComputationAction1 in its handling of
+ * instance variables. ComputationAction1 has a simple <Code>nameStr</code>
+ * instance variable. This variable is set when the begin() method is called
+ * and then later used within the end() method.
+ *
+ * This simple approach works properly if the begin() and end()
+ * method of a given action are expected to be called in sequence. However,
+ * there are situations where the begin() method of the same action instance is
+ * invoked multiple times before the matching end() method is invoked.
+ *
+ * When this happens, the second call to begin() overwrites values set by
+ * the first invocation to begin(). The solution is to save parameter values
+ * into a separate stack. The well-formedness of XML will guarantee that a value
+ * saved by one begin() will be consumed only by the matching end() method.
+ *
+ * Note that in the vast majority of cases there is no need to resort to a
+ * separate stack for each variable. The situation of successibe begin()
+ * invocations can only occur if:
+ *
+ * 1) the associated pattern contains a wildcard, i.e. the * character
+ *
+ * and
+ *
+ * 2) the associated element tag can contain itself as a child
+ *
+ * For example, "*/computation" pattern means that computations can contain
+ * other computation elements as children.
+ *
+ * @author Ceki Gülcü
+ */
+public class ComputationAction2 extends Action {
+ public static String NAME_ATR = "name";
+
+ Stack<String> nameStrStack = new Stack<String>();
+
+
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ String nameStr = attributes.getValue(NAME_ATR);
+ // save nameStr value in a special stack. Note that the value is saved
+ // even if it is empty or null.
+ nameStrStack.push(nameStr);
+ }
+
+ public void end(InterpretationContext ec, String name) {
+ // pop nameStr value from the special stack
+ String nameStr = (String) nameStrStack.pop();
+
+ if (OptionHelper.isEmpty(nameStr)) {
+ // nothing to do
+ } else {
+ Integer i = (Integer) ec.peekObject();
+ System.out.println(
+ "The computation named [" + nameStr + "] resulted in the value " + i);
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/LiteralAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/LiteralAction.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,56 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.util.OptionHelper;
+
+/**
+ *
+ * This action converts the value attribute of the associated element to
+ * an integer and pushes the resulting Integer object on top of the execution
+ * context stack.
+ *
+ * It also illustrates usage of Joran's error handling paradigm.
+ *
+ * @author Ceki Gülcü
+ */
+public class LiteralAction extends Action {
+ public static String VALUE_ATR = "value";
+
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ String valueStr = attributes.getValue(VALUE_ATR);
+
+ if (OptionHelper.isEmpty(valueStr)) {
+ ec.addError("The literal action requires a value attribute");
+ return;
+ }
+
+ try {
+ Integer i = Integer.valueOf(valueStr);
+ ec.pushObject(i);
+ } catch (NumberFormatException nfe) {
+ ec.addError("The value [" + valueStr + "] could not be converted to an Integer",
+ nfe);
+ throw nfe;
+ }
+ }
+
+ public void end(InterpretationContext ec, String name) {
+ // Nothing to do here.
+ // In general, the end() method of actions associated with elements
+ // having no children do not need to perform any processing in their
+ // end() method.
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/MultiplyAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/MultiplyAction.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,70 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, 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 joran.calculator;
+
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+
+import java.util.EmptyStackException;
+
+
+/**
+ *
+ * This action multiplies the two integers at the top of the stack (they are removed)
+ * and pushes the result on top the stack.
+ *
+ * @author Ceki Gülcü
+ */
+public class MultiplyAction extends Action {
+
+
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ int first = fetchInteger(ec);
+ int second = fetchInteger(ec);
+ ec.pushObject(new Integer(first * second));
+ }
+
+ /**
+ * Pop the Integer object at the top of the stack.
+ * This code illustrates usage of Joran's error handling paradigm.
+ */
+ int fetchInteger(InterpretationContext ec) {
+ int result = 0;
+
+ try {
+ Object o1 = ec.popObject();
+
+ if (o1 instanceof Integer) {
+ result = ((Integer) o1).intValue();
+ } else {
+ String errMsg =
+ "Object [" + o1
+ + "] currently at the top of the stack is not an integer.";
+ ec.addError(errMsg);
+ throw new IllegalArgumentException(errMsg);
+ }
+ } catch (EmptyStackException ese) {
+ ec.addError("Expecting an integer on the execution stack.");
+ throw ese;
+ }
+ return result;
+ }
+
+ public void end(InterpretationContext ec, String name) {
+ // Nothing to do here.
+ // In general, the end() method of actions associated with elements
+ // having no children do not need to perform any processing in their
+ // end() method.
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/calculator1.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/calculator1.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE computation>
+
+<computation name="total">
+ <literal value="3"/>
+</computation>
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/calculator2.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/calculator2.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE computation>
+
+<computation name="toto">
+ <literal value="7"/>
+ <literal value="3"/>
+ <add/>
+ <literal value="3"/>
+ <multiply/>
+</computation>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/calculator3.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/calculator3.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE computation>
+
+<!-- This file is intended to be executed by Caculator2.
+ It is not suited for Calculator1 due to nested computation
+ elements.
+ -->
+
+<computation name="toto">
+ <computation>
+ <literal value="7"/>
+ <literal value="3"/>
+ <add/>
+ </computation>
+
+ <literal value="3"/>
+ <multiply/>
+</computation>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/joran/calculator/readme.txt
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/calculator/readme.txt Fri Oct 27 14:53:15 2006
@@ -0,0 +1,17 @@
++------------------------------+
+| |
+| Joran Examples |
+| |
+| Calculator |
+| |
++------------------------------+
+
+This directory contains the the calculator example.
+
+It shows how Actions can collaborate in order to accomplish a simple
+computation.
+
+For more in-depth informations about this example, please visit:
+
+http://logback.qos.ch/joran.html#calculator
+
Added: logback/trunk/logback-examples/src/main/java/joran/helloWorld/HelloWorld.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/helloWorld/HelloWorld.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,60 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.helloWorld;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import joran.SimpleConfigurator;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.util.StatusPrinter;
+
+
+/**
+ *
+ * A hello world example using Joran.
+ *
+ * The first and only argument of this application must be the path to
+ * the XML file to interpret.
+ *
+ * For example,
+ *
+<pre>
+ java joran.helloWorld.HelloWorld examples/src/joran/helloWorld/hello.xml
+</pre>
+ *
+ * @author Ceki Gulcu
+ */
+public class HelloWorld {
+ public static void main(String[] args) throws Exception {
+ Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>();
+
+ // Associate "hello-world" pattern with HelloWorldAction
+ ruleMap.put(new Pattern("hello-world"), new HelloWorldAction());
+
+ // Joran needs to work within a context.
+ Context context = new ContextBase();
+ SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
+ // link the configurator with its context
+ simpleConfigurator.setContext(context);
+
+ try {
+ simpleConfigurator.doConfigure(args[0]);
+ } catch (JoranException e) {
+ // Print any errors that might have occured.
+ StatusPrinter.print(context);
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/helloWorld/HelloWorldAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/helloWorld/HelloWorldAction.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,35 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.helloWorld;
+
+
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+
+
+/**
+ * A trivial action that writes "Hello world" on the console.
+ *
+ * See the HelloWorld class for integrating with Joran.
+ *
+ * @author Ceki Gülcü
+ */
+public class HelloWorldAction extends Action {
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ System.out.println("Hello World");
+ }
+
+ public void end(InterpretationContext ec, String name) {
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/helloWorld/hello.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/helloWorld/hello.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE hello-world>
+
+<hello-world>
+</hello-world>
Added: logback/trunk/logback-examples/src/main/java/joran/helloWorld/readme.txt
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/helloWorld/readme.txt Fri Oct 27 14:53:15 2006
@@ -0,0 +1,16 @@
++------------------------------+
+| |
+| Joran Examples |
+| |
+| Hello World |
+| |
++------------------------------+
+
+This directory contains the simplest examples of the Joran tutorial.
+
+It includes a trivial action and a sample setup of Joran Interpreter.
+
+For more in-depth informations about this example, please visit:
+
+http://logback.qos.ch/joran.html#helloWorld
+
Added: logback/trunk/logback-examples/src/main/java/joran/implicit/NOPAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/implicit/NOPAction.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,32 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.implicit;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+
+
+
+/**
+ * No operation (NOP) action that does strictly nothing.
+ *
+ * @author Ceki Gülcü
+ */
+public class NOPAction extends Action {
+
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ }
+
+
+ public void end(InterpretationContext ec, String name) {
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/implicit/PrintMe.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/implicit/PrintMe.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,67 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, 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 joran.implicit;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import joran.SimpleConfigurator;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.action.ImplicitAction;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.util.StatusPrinter;
+
+
+/**
+ * This example illustrates the usage of implcit actions.
+ *
+ * The crucial point to remember about implicit actions is that they
+ * are not associated with a pattern. Moreover, they are added directly to
+ * a Joran Interpreter instead of a rule store.
+ *
+ * @author Ceki Güulcü
+ */
+public class PrintMe {
+
+
+ public static void main(String[] args) throws Exception {
+ Context context = new ContextBase();
+
+ Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>();
+
+
+ // we start with the rule for the top-most (root) element
+ ruleMap.put(new Pattern("*/foo"), new NOPAction());
+
+
+ List<ImplicitAction> iaList = new ArrayList<ImplicitAction>();
+ // --------------------------+
+ // Add an implicit action. |
+ // --------------------------+
+ iaList.add(new PrintMeImplicitAction());
+
+ SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap, iaList);
+ // link the configurator with its context
+ simpleConfigurator.setContext(context);
+
+ try {
+ simpleConfigurator.doConfigure(args[0]);
+ } catch (JoranException e) {
+ // Print any errors that might have occured.
+ StatusPrinter.print(context);
+ }
+
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/implicit/PrintMeImplicitAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/implicit/PrintMeImplicitAction.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,44 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.implicit;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.ImplicitAction;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.joran.spi.Pattern;
+
+
+
+/**
+ *
+ * A rather trivial implicit action which is applicable as soon as an
+ * element has a printme attribute set to true.
+ *
+ * @author Ceki Gülcü
+ */
+public class PrintMeImplicitAction extends ImplicitAction {
+
+ public boolean isApplicable(
+ Pattern pattern, Attributes attributes, InterpretationContext ec) {
+ String printmeStr = attributes.getValue("printme");
+
+ return Boolean.valueOf(printmeStr).booleanValue();
+ }
+
+ public void begin(InterpretationContext ec, String name, Attributes attributes) {
+ System.out.println("Element <"+name+"> asked to be printed.");
+ }
+
+
+ public void end(InterpretationContext ec, String name) {
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/implicit/implicit1.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/implicit/implicit1.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE foo>
+
+<foo>
+
+ <!-- These elements will print due to the implcit rule -->
+ <xyz printme="true">
+ <abc printme="true"/>
+ </xyz>
+
+ <!-- This element has no associated rule and no implicit rule
+ applies for it because the printme attribute is not set. -->
+ <xyz/>
+
+
+
+ <!-- This element will not be printed even if its printme
+ attribute is set because implicit rules are invoked only
+ if no explicit rule matches the element. The */foo rule
+ mathches the following element.
+ -->
+ <foo printme="true"/>
+
+</foo>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/joran/implicit/readme.txt
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/implicit/readme.txt Fri Oct 27 14:53:15 2006
@@ -0,0 +1,17 @@
++------------------------------+
+| |
+| Joran Examples |
+| |
+| Implicit |
+| |
++------------------------------+
+
+This directory contains the implicit action example.
+
+It shows how to use implicit actions, which do not require an explicit
+pattern.
+
+For more in-depth informations about this example, please visit:
+
+http://logback.qos.ch/joran.html#implicit
+
Added: logback/trunk/logback-examples/src/main/java/joran/newRule/NewRuleCalculator.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/newRule/NewRuleCalculator.java Fri Oct 27 14:53:15 2006
@@ -0,0 +1,65 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, 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 joran.newRule;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import joran.SimpleConfigurator;
+import joran.calculator.ComputationAction2;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.action.NewRuleAction;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.util.StatusPrinter;
+
+
+/**
+ * This example illustrates the usage of NewRuleAction which allows the Joran
+ * interpreter to learn new rules on the fly from the XML file being
+ * interpreted.
+ *
+ * This example relies heavily on the code from the joran.calculator package.
+ *
+ * @author Ceki Güulcü
+ */
+public class NewRuleCalculator {
+ public static void main(String[] args) throws Exception {
+
+ Context context = new ContextBase();
+
+
+ Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>();
+
+ // we start with the rule for the top-most (root) element
+ ruleMap.put(new Pattern("*/computation"), new ComputationAction2());
+
+ // Associate "/new-rule" pattern with NewRuleAction from the
+ // org.apache.joran.action package.
+ //
+ // We will let the XML file to teach the Joran interpreter about new rules
+ ruleMap.put(
+ new Pattern("/computation/new-rule"), new NewRuleAction());
+
+ SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
+ // link the configurator with its context
+ simpleConfigurator.setContext(context);
+
+ try {
+ simpleConfigurator.doConfigure(args[0]);
+ } catch (JoranException e) {
+ // Print any errors that might have occured.
+ StatusPrinter.print(context);
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/joran/newRule/new-rule.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/newRule/new-rule.xml Fri Oct 27 14:53:15 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE computation>
+
+<!-- This file is intended to be executed by NewRuleCalculator.
+ Note that the rules for adding and multiplying are learned on the fly, while parsing
+ this file.
+ -->
+
+
+
+<computation name="toto">
+ <new-rule pattern="*/computation/literal"
+ actionClass="joran.calculator.LiteralAction"/>
+ <new-rule pattern="*/computation/add"
+ actionClass="joran.calculator.AddAction"/>
+ <new-rule pattern="*/computation/multiply"
+ actionClass="joran.calculator.MultiplyAction"/>
+
+ <computation>
+ <literal value="7"/>
+ <literal value="3"/>
+ <add/>
+ </computation>
+
+ <literal value="3"/>
+ <multiply/>
+</computation>
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/joran/newRule/readme.txt
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/joran/newRule/readme.txt Fri Oct 27 14:53:15 2006
@@ -0,0 +1,17 @@
++------------------------------+
+| |
+| Joran Examples |
+| |
+| New rule |
+| |
++------------------------------+
+
+This directory contains an example using the new rule action.
+
+It shows how Joran can learn new rules on the fly, while interpreting
+the xml file.
+
+For more in-depth informations about this example, please visit:
+
+http://logback.qos.ch/joran.html#newRule
+
Modified: logback/trunk/pom.xml
==============================================================================
--- logback/trunk/pom.xml (original)
+++ logback/trunk/pom.xml Fri Oct 27 14:53:15 2006
@@ -22,6 +22,7 @@
<module>logback-access</module>
<module>logback-site</module>
<module>logback-skin</module>
+ <module>logback-examples</module>
</modules>
<dependencies>
@@ -50,6 +51,18 @@
</dependency>
<dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-access</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>janino</groupId>
<artifactId>janino</artifactId>
<version>2.4.3</version>
Modified: logback/trunk/src/main/assembly/dist.xml
==============================================================================
--- logback/trunk/src/main/assembly/dist.xml (original)
+++ logback/trunk/src/main/assembly/dist.xml Fri Oct 27 14:53:15 2006
@@ -14,6 +14,9 @@
pom.xml
</include>
</includes>
+ <excludes>
+ <exclude>*.bak</exclude>
+ </excludes>
</fileSet>
<fileSet>
<directory>logback-classic/</directory>
@@ -23,8 +26,11 @@
pom.xml
</include>
</includes>
+ <excludes>
+ <exclude>*.bak</exclude>
+ </excludes>
</fileSet>
- <fileSet>
+ <fileSet>
<directory>logback-access/</directory>
<outputDirectory>logback-access/</outputDirectory>
<includes>
@@ -32,6 +38,21 @@
pom.xml
</include>
</includes>
+ <excludes>
+ <exclude>*.bak</exclude>
+ </excludes>
+ </fileSet>
+ <fileSet>
+ <directory>logback-examples/</directory>
+ <outputDirectory>logback-examples/</outputDirectory>
+ <includes>
+ <include>
+ pom.xml
+ </include>
+ </includes>
+ <excludes>
+ <exclude>*.bak</exclude>
+ </excludes>
</fileSet>
<!-- Module Source directories -->
@@ -52,6 +73,15 @@
<directory>logback-access/src/</directory>
<outputDirectory>logback-access/src/</outputDirectory>
</fileSet>
+ <fileSet>
+ <directory>logback-examples/src/</directory>
+ <outputDirectory>logback-examples/src/</outputDirectory>
+ </fileSet>
+ <!-- We also include the classes of the examples module -->
+ <fileSet>
+ <directory>logback-examples/target/classes/</directory>
+ <outputDirectory>logback-examples/classes/</outputDirectory>
+ </fileSet>
<!-- Module JARs -->
<fileSet>
@@ -101,18 +131,19 @@
</includes>
</fileSet>
- <!-- Classic Examples -->
+ <!-- Classic Examples
<fileSet>
<directory>logback-classic/examples/</directory>
<outputDirectory>/examples/</outputDirectory>
</fileSet>
-
- <!-- Core Examples -->
+ -->
+ <!-- Core Examples
<fileSet>
<directory>logback-core/examples/</directory>
<outputDirectory>/examples/</outputDirectory>
</fileSet>
-
+ -->
+
<!-- Website -->
<fileSet>
<directory>target/site</directory>
@@ -127,6 +158,9 @@
<include>LICENSE*</include>
<include>pom.xml</include>
</includes>
+ <excludes>
+ <exclude>*.bak</exclude>
+ </excludes>
</fileSet>
</fileSets>
1
0
Author: seb
Date: Fri Oct 27 11:23:28 2006
New Revision: 798
Added:
logback/trunk/sync_logback_ibiblio.sh
Log:
added sync script
Added: logback/trunk/sync_logback_ibiblio.sh
==============================================================================
--- (empty file)
+++ logback/trunk/sync_logback_ibiblio.sh Fri Oct 27 11:23:28 2006
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+FROM=rsync://logback.qos.ch/dist/bundles/
+TO=ch/qos/logback
+
+NO_SSH=true
\ No newline at end of file
1
0

svn commit: r797 - in logback/trunk/logback-classic: . src/test/java/ch/qos/logback/classic src/test/java/ch/qos/logback/classic/boolex src/test/java/ch/qos/logback/classic/db src/test/java/ch/qos/logback/classic/html
by noreply.ceki@qos.ch 27 Oct '06
by noreply.ceki@qos.ch 27 Oct '06
27 Oct '06
Author: ceki
Date: Fri Oct 27 06:23:34 2006
New Revision: 797
Added:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java
Modified:
logback/trunk/logback-classic/mdcfilter.xml
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
Log:
- improvements to tests
Modified: logback/trunk/logback-classic/mdcfilter.xml
==============================================================================
--- logback/trunk/logback-classic/mdcfilter.xml (original)
+++ logback/trunk/logback-classic/mdcfilter.xml Fri Oct 27 06:23:34 2006
@@ -1,11 +1,12 @@
<configuration>
<appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
+ class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<param name="Pattern"
value="%-4relative [%thread] %-5level %X{testKey} - %msg%n" />
</layout>
+
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<Name>myFilter</Name>
<OnMatch>DENY</OnMatch>
@@ -13,11 +14,9 @@
<Name>mdcEvaluator</Name>
<Expression>mdc!=null && "val".equals(mdc.get("key"))</Expression>
</Evaluator>
-
</filter>
</appender>
-
<root>
<level value="debug" />
<appender-ref ref="STDOUT" />
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java Fri Oct 27 06:23:34 2006
@@ -21,9 +21,13 @@
suite.addTest(ch.qos.logback.classic.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.boolex.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());
-
+ suite.addTest(ch.qos.logback.classic.db.PackageTest.suite());
+
return suite;
}
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java Fri Oct 27 06:23:34 2006
@@ -4,16 +4,15 @@
import org.slf4j.MarkerFactory;
-import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
import ch.qos.logback.classic.pattern.ConverterTest;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.boolex.EvaluationException;
+import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
import ch.qos.logback.core.boolex.Matcher;
-
public class JaninoEventEvaluatorTest extends TestCase {
LoggerContext loggerContext = new LoggerContext();
@@ -31,8 +30,9 @@
}
LoggingEvent makeLoggingEvent(Exception ex) {
- LoggingEvent e = new LoggingEvent(ch.qos.logback.core.pattern.FormattingConverter.class
- .getName(), logger, Level.INFO, "Some message", ex, null);
+ LoggingEvent e = new LoggingEvent(
+ ch.qos.logback.core.pattern.FormattingConverter.class.getName(),
+ logger, Level.INFO, "Some message", ex, null);
return e;
}
@@ -103,15 +103,16 @@
try {
jee.evaluate(event);
fail("We should not reach this point");
- } catch(EvaluationException ee) {
-
+ } catch (EvaluationException ee) {
+
}
}
-
+
public void testComplex() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
- jee.setExpression("level >= INFO && x.matches(message) && marker.contains(\"BLUE\")");
+ jee
+ .setExpression("level >= INFO && x.matches(message) && marker.contains(\"BLUE\")");
jee.setContext(loggerContext);
jee.addMatcher(matcherX);
jee.start();
@@ -121,7 +122,54 @@
assertTrue(jee.evaluate(event));
}
- static final long LEN = 100 * 1000;
+ /**
+ * check that evaluator with bogis exp does not start
+ *
+ * @throws Exception
+ */
+ public void testBogusExp1() {
+
+ JaninoEventEvaluator jee = new JaninoEventEvaluator();
+ jee.setExpression("mzzzz.get(\"key\").equals(null)");
+ jee.setContext(loggerContext);
+ jee.setName("bogus");
+ jee.start();
+
+ assertFalse(jee.isStarted());
+
+ // StatusPrinter.print(loggerContext);
+ // LoggingEvent event = makeLoggingEvent(null);
+ // event.setMarker(MarkerFactory.getMarker("BLUE"));
+ //
+ // jee.evaluate(event);
+ }
+
+ // check that eval stops after errors
+ public void testBogusExp2() {
+
+ JaninoEventEvaluator jee = new JaninoEventEvaluator();
+ jee.setExpression("mdc.get(\"key\").equals(null)");
+ jee.setContext(loggerContext);
+ jee.setName("bogus");
+ jee.start();
+
+ assertTrue(jee.isStarted());
+
+ LoggingEvent event = makeLoggingEvent(null);
+
+ for (int i = 0; i < JaninoEventEvaluatorBase.ERROR_THRESHOLD; i++) {
+ try {
+ jee.evaluate(event);
+ fail("should throw an exception");
+ } catch (EvaluationException e) {
+ }
+ }
+ // after a few attempts the evaluator should stop
+ assertFalse(jee.isStarted());
+
+ }
+
+ static final long LEN = 10 * 1000;
// with 6 parameters 400 nanos
// with 7 parameters 460 nanos (all levels + selected fields from
@@ -130,7 +178,6 @@
void loop(JaninoEventEvaluator jee, String msg) throws Exception {
LoggingEvent event = makeLoggingEvent(null);
final long start = System.nanoTime();
- final long LEN = 500 * 1000;
for (int i = 0; i < LEN; i++) {
jee.evaluate(event);
}
@@ -156,5 +203,5 @@
loop(jee, "x.matches(message): ");
}
-
+
}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java Fri Oct 27 06:23:34 2006
@@ -0,0 +1,21 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, 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.boolex;
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(JaninoEventEvaluatorTest.class);
+ return suite;
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java Fri Oct 27 06:23:34 2006
@@ -0,0 +1,21 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, 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.db;
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(DBAppenderTest.class);
+ return suite;
+ }
+}
\ No newline at end of file
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java Fri Oct 27 06:23:34 2006
@@ -0,0 +1,21 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, 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.html;
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(HTMLLayoutTest.class);
+ return suite;
+ }
+}
\ No newline at end of file
1
0

svn commit: r796 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/boolex main/java/ch/qos/logback/core/filter test/java/ch/qos/logback/core/util
by noreply.ceki@qos.ch 27 Oct '06
by noreply.ceki@qos.ch 27 Oct '06
27 Oct '06
Author: ceki
Date: Fri Oct 27 06:22:28 2006
New Revision: 796
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java
Log:
- JaninoEvaluator stops itself after several errors
- corrected a hard to spot bug in AbstractEvaluatorFilter. It has methods like
public int getOnMatch()
public void setOnMatch(String)
public int getOnMismatch()
public void setOnMismatch(String)
The fact that the getter returned an int and the setter took a String has PropertySetter confused.
I removed the getOn*match methods which were not used anywhere.
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java Fri Oct 27 06:22:28 2006
@@ -1,7 +1,5 @@
package ch.qos.logback.core.boolex;
-
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -10,29 +8,36 @@
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
-abstract public class JaninoEventEvaluatorBase extends ContextAwareBase implements
- EventEvaluator, LifeCycle {
+abstract public class JaninoEventEvaluatorBase extends ContextAwareBase
+ implements EventEvaluator, LifeCycle {
static Class EXPRESSION_TYPE = boolean.class;
static Class[] THROWN_EXCEPTIONS = new Class[1];
+ static public final int ERROR_THRESHOLD = 4;
static {
THROWN_EXCEPTIONS[0] = EvaluationException.class;
}
+
+
protected boolean start = false;
private String name;
private String expression;
ExpressionEvaluator ee;
+ private int errorCount = 0;
abstract protected String getDecoratedExpression();
+
abstract protected String[] getParameterNames();
+
abstract protected Class[] getParameterTypes();
+
abstract protected Object[] getParameterValues(Object event);
- protected List<Matcher> matcherList = new ArrayList<Matcher> ();
-
+ protected List<Matcher> matcherList = new ArrayList<Matcher>();
+
public boolean isStarted() {
return start;
}
@@ -43,23 +48,29 @@
public void start() {
try {
- ee = new ExpressionEvaluator(getDecoratedExpression(),
- EXPRESSION_TYPE, getParameterNames(), getParameterTypes(),
- THROWN_EXCEPTIONS, null);
+ ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE,
+ getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, null);
start = true;
} catch (Exception e) {
- addError("Could not start evaluator with expression [" + expression + "]", e);
+ addError(
+ "Could not start evaluator with expression [" + expression + "]", e);
}
}
- public boolean evaluate(Object event) throws NullPointerException,
- EvaluationException {
+ public boolean evaluate(Object event) throws EvaluationException {
+ if (!start) {
+ throw new IllegalStateException("Evaluator [" + name + "] was called in stopped state");
+ }
try {
Boolean result = (Boolean) ee.evaluate(getParameterValues(event));
return result.booleanValue();
- } catch (InvocationTargetException ite) {
+ } catch (Exception ex) {
+ errorCount++;
+ if (errorCount >= ERROR_THRESHOLD) {
+ start = false;
+ }
throw new EvaluationException("Evaluator [" + name
- + "] caused an exception", ite);
+ + "] caused an exception", ex);
}
}
@@ -81,11 +92,11 @@
public void setExpression(String expression) {
this.expression = expression;
}
-
+
public void addMatcher(Matcher matcher) {
matcherList.add(matcher);
}
-
+
public List getMatcherList() {
return matcherList;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java Fri Oct 27 06:22:28 2006
@@ -5,7 +5,7 @@
* This abstract class is meant to be a base for specific evaluator filters.
* </p>
* <p>
- * The value of the {@link #onMatch} and {@link #onMismatch} attributes is set to
+ * The value of the {@link #on_match} and {@link #onMismatch} attributes is set to
* {@link Filter.NEUTRAL}, so that a badly configured evaluator filter doesn't
* disturb the functionning of the chain.
* </p>
@@ -19,23 +19,22 @@
*
*/
-abstract public class AbstractEvalutatorFilter extends Filter {
+public abstract class AbstractEvalutatorFilter extends Filter {
- int onMatch = NEUTRAL;
- int onMismatch = NEUTRAL;
+ protected int on_match = NEUTRAL;
+ protected int onMismatch = NEUTRAL;
-
- public void setOnMatch(String action) {
+ final public void setOnMatch(String action) {
if ("NEUTRAL".equals(action)) {
- onMatch = NEUTRAL;
+ on_match = NEUTRAL;
} else if ("ACCEPT".equals(action)) {
- onMatch = ACCEPT;
+ on_match = ACCEPT;
} else if ("DENY".equals(action)) {
- onMatch = DENY;
+ on_match = DENY;
}
}
- public void setOnMismatch(String action) {
+ final public void setOnMismatch(String action) {
if ("NEUTRAL".equals(action)) {
onMismatch = NEUTRAL;
} else if ("ACCEPT".equals(action)) {
@@ -44,12 +43,4 @@
onMismatch = DENY;
}
}
-
- public int getOnMatch() {
- return onMatch;
- }
-
- public int getOnMistmatch() {
- return onMismatch;
- }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java Fri Oct 27 06:22:28 2006
@@ -7,20 +7,6 @@
EventEvaluator evaluator;
- public EvaluatorFilter() {
- }
-
-
- public void setX(String action) {
- if ("NEUTRAL".equals(action)) {
- onMatch = NEUTRAL;
- } else if ("ACCEPT".equals(action)) {
- onMatch = ACCEPT;
- } else if ("DENY".equals(action)) {
- onMatch = DENY;
- }
- }
-
public void start() {
if(evaluator != null) {
super.start();
@@ -46,7 +32,7 @@
}
try {
if (evaluator.evaluate(event)) {
- return onMatch;
+ return on_match;
} else {
return onMismatch;
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java Fri Oct 27 06:22:28 2006
@@ -46,6 +46,20 @@
}
}
+ public void testSetCamelProperty() {
+ House house = new House();
+ PropertySetter setter = new PropertySetter(house);
+
+ setter.setProperty("camelCase", "trot");
+ assertEquals("trot", house.getCamelCase());
+
+ setter.setProperty("camelCase", "gh");
+ assertEquals("gh", house.getCamelCase());
+
+ setter.setProperty("OnMatch", "raven");
+ assertEquals("raven", house.getOnMatch());
+
+ }
public void testSetComponent() {
House house = new House();
Door door = new Door();
@@ -61,6 +75,24 @@
int count;
boolean open;
String name;
+ String camelCase;
+ String onMatch;
+
+ public String getOnMatch() {
+ return onMatch;
+ }
+
+ public void setOnMatch(String onMatch) {
+ this.onMatch = onMatch;
+ }
+
+ public String getCamelCase() {
+ return camelCase;
+ }
+
+ public void setCamelCase(String camelCase) {
+ this.camelCase = camelCase;
+ }
public int getCount() {
return count;
1
0
October 26th, 2006 - Release of logback 0.5
Version 0.5 for all three logback modules is now available.
This release offers a big improvement in Joran. Joran is now able to replay
configuration elements.
Logback's documentation has also been improved. A complete reference on Layouts is
available in the logback manual directory, as well as a FAQ page.
You can download the modules, including full source code, class files and
documentation on our download page, shown below.
http://logback.qos.ch/download.html
You can receive logback related announcements by subscribing
to the logback announce mailing list. To subscribe to logback-announce
list, please visit the following URL.
http://logback.qos.ch/mailinglist.html
--
Sébastien Pennec
sebastien(a)qos.ch
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch/
1
0

svn commit: r795 - in logback/trunk: . logback-access logback-classic logback-core logback-site logback-skin
by noreply.seb@qos.ch 26 Oct '06
by noreply.seb@qos.ch 26 Oct '06
26 Oct '06
Author: seb
Date: Thu Oct 26 17:14:36 2006
New Revision: 795
Modified:
logback/trunk/logback-access/pom.xml
logback/trunk/logback-classic/pom.xml
logback/trunk/logback-core/pom.xml
logback/trunk/logback-site/pom.xml
logback/trunk/logback-skin/pom.xml
logback/trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: logback/trunk/logback-access/pom.xml
==============================================================================
--- logback/trunk/logback-access/pom.xml (original)
+++ logback/trunk/logback-access/pom.xml Thu Oct 26 17:14:36 2006
@@ -3,14 +3,14 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Logback Access Module</name>
Modified: logback/trunk/logback-classic/pom.xml
==============================================================================
--- logback/trunk/logback-classic/pom.xml (original)
+++ logback/trunk/logback-classic/pom.xml Thu Oct 26 17:14:36 2006
@@ -3,14 +3,14 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Logback Classic Module</name>
Modified: logback/trunk/logback-core/pom.xml
==============================================================================
--- logback/trunk/logback-core/pom.xml (original)
+++ logback/trunk/logback-core/pom.xml Thu Oct 26 17:14:36 2006
@@ -3,14 +3,14 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Logback Core Module</name>
Modified: logback/trunk/logback-site/pom.xml
==============================================================================
--- logback/trunk/logback-site/pom.xml (original)
+++ logback/trunk/logback-site/pom.xml Thu Oct 26 17:14:36 2006
@@ -3,7 +3,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -11,7 +11,7 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-site</artifactId>
<packaging>jar</packaging>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
<name>Logback Site</name>
<url>http://logback.qos.ch</url>
Modified: logback/trunk/logback-skin/pom.xml
==============================================================================
--- logback/trunk/logback-skin/pom.xml (original)
+++ logback/trunk/logback-skin/pom.xml Thu Oct 26 17:14:36 2006
@@ -3,7 +3,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
</parent>
@@ -12,7 +12,7 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-skin</artifactId>
<packaging>jar</packaging>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
<name>Logback Skin</name>
<url>http://logback.qos.ch</url>
Modified: logback/trunk/pom.xml
==============================================================================
--- logback/trunk/pom.xml (original)
+++ logback/trunk/pom.xml Thu Oct 26 17:14:36 2006
@@ -4,7 +4,7 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
- <version>0.5</version>
+ <version>0.6-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Logback</name>
@@ -192,9 +192,9 @@
</reporting>
<scm>
- <connection>scm:svn:https://svn.qos.ch/repos/logback/tags/release-0.5</connection>
- <developerConnection>scm:svn:https://svn.qos.ch/repos/logback/tags/release-0.5</developerConnection>
- <url>https://svn.qos.ch/repos/logback/tags/release-0.5</url>
+ <connection>http://svn.qos.ch/repos/logback/</connection>
+ <developerConnection>scm:svn:https://svn.qos.ch/repos/logback/</developerConnection>
+ <url>http://svn.qos.ch/viewvc/logback/</url>
</scm>
<distributionManagement>
1
0

svn commit: r794 - in logback/tags/release-0.5: . logback-access logback-access/src/test/java/ch/qos/logback/access/jetty logback-classic logback-core logback-site logback-site/src/site/xdocTemplates logback-skin src/main/assembly
by noreply.seb@qos.ch 26 Oct '06
by noreply.seb@qos.ch 26 Oct '06
26 Oct '06
Author: seb
Date: Thu Oct 26 17:14:34 2006
New Revision: 794
Added:
logback/tags/release-0.5/
- copied from r776, /logback/trunk/
logback/tags/release-0.5/logback-access/
- copied from r787, /logback/trunk/logback-access/
logback/tags/release-0.5/logback-access/pom.xml
- copied unchanged from r793, /logback/trunk/logback-access/pom.xml
logback/tags/release-0.5/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyTestSetup.java
- copied unchanged from r790, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyTestSetup.java
logback/tags/release-0.5/logback-classic/
- copied from r787, /logback/trunk/logback-classic/
logback/tags/release-0.5/logback-classic/pom.xml
- copied unchanged from r793, /logback/trunk/logback-classic/pom.xml
logback/tags/release-0.5/logback-core/
- copied from r787, /logback/trunk/logback-core/
logback/tags/release-0.5/logback-core/pom.xml
- copied unchanged from r793, /logback/trunk/logback-core/pom.xml
logback/tags/release-0.5/logback-site/
- copied from r787, /logback/trunk/logback-site/
logback/tags/release-0.5/logback-site/pom.xml
- copied unchanged from r793, /logback/trunk/logback-site/pom.xml
logback/tags/release-0.5/logback-site/src/site/xdocTemplates/news.xml
- copied unchanged from r788, /logback/trunk/logback-site/src/site/xdocTemplates/news.xml
logback/tags/release-0.5/logback-skin/
- copied from r787, /logback/trunk/logback-skin/
logback/tags/release-0.5/logback-skin/pom.xml
- copied unchanged from r793, /logback/trunk/logback-skin/pom.xml
logback/tags/release-0.5/pom.xml
- copied unchanged from r793, /logback/trunk/pom.xml
logback/tags/release-0.5/src/main/assembly/dist.xml
- copied unchanged from r788, /logback/trunk/src/main/assembly/dist.xml
Log:
[maven-scm] copy for tag release-0.5
1
0