[logback-dev] svn commit: r799 - in logback/trunk: . logback-examples logback-examples/src logback-examples/src/main logback-examples/src/main/java logback-examples/src/main/java/chapter1 logback-examples/src/main/java/chapter4 logback-examples/src/main/java/chapter4/conf logback-examples/src/main/java/chapter4/sub logback-examples/src/main/java/chapter4/sub/sample logback-examples/src/main/java/chapter5 logback-examples/src/main/java/joran logback-examples/src/main/java/joran/calculator logback-examples/src/main/java/joran/helloWorld logback-examples/src/main/java/joran/implicit logback-examples/src/main/java/joran/newRule src/main/assembly

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Oct 27 14:53:16 CEST 2006


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&eacute;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 at qos.ch" />
+    <param name="SMTPHost" value="mail.qos.ch" />
+    
+    <param name="Subject" value="Last Event: %-10logger %nopex" />
+    
+    <param name="To" value="sebastien at 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 at qos.ch" />
+    <param name="SMTPHost" value="mail.qos.ch" />
+    <param name="Subject" value="LastEvent: %class - %msg %nopex" />
+    
+    <param name="To" value="sebastien at 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") &amp;&amp; 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 &amp;&amp; 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 &amp;&amp; "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&uuml;lc&uuml;
+ */
+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&uuml;ulc&uuml;
+ */
+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&uuml;ulc&uuml;
+ */
+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&uuml;lc&uuml;
+ */
+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 &#42; character
+ * 
+ * and
+ * 
+ * 2) the associated element tag can contain itself as a child 
+ *  
+ * For example, "&#42;/computation" pattern means that computations can contain
+ * other computation elements as children. 
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ */
+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&uuml;lc&uuml;
+ */
+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&uuml;lc&uuml;
+ */
+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&uuml;lc&uuml;
+ */
+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&uuml;lc&uuml;
+ */
+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&uuml;ulc&uuml;
+ */
+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&uuml;lc&uuml;
+ */
+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&uuml;ulc&uuml;
+ */
+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>
 	



More information about the logback-dev mailing list