[logback-dev] svn commit: r602 - in logback/trunk/logback-classic/examples/src/chapter4: . conf sub sub/sample

noreply.seb at qos.ch noreply.seb at qos.ch
Mon Sep 25 17:01:51 CEST 2006


Author: seb
Date: Mon Sep 25 17:01:50 2006
New Revision: 602

Added:
   logback/trunk/logback-classic/examples/src/chapter4/
   logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java
   logback/trunk/logback-classic/examples/src/chapter4/conf/
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-Console.xml
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-HtmlToConsole.xml
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-MDC.xml
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-RollingSizeBased.xml
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-RollingTimeBased.xml
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-SMTP.xml
   logback/trunk/logback-classic/examples/src/chapter4/conf/logback-SMTPWithHtml.xml
   logback/trunk/logback-classic/examples/src/chapter4/sub/
   logback/trunk/logback-classic/examples/src/chapter4/sub/sample/
   logback/trunk/logback-classic/examples/src/chapter4/sub/sample/Bar.java

Log:
- added a chapter4 package in the examples, containing several configuration files for logback, as well as
a ConfigurationTester class to launch logback with a specified config. file.

Added: logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java	Mon Sep 25 17:01:50 2006
@@ -0,0 +1,43 @@
+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.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();
+
+    JoranConfigurator configurator = new JoranConfigurator();
+    configurator.setContext(lc);
+    configurator.doConfigure(args[0]);
+
+    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-classic/examples/src/chapter4/conf/logback-Console.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-Console.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/conf/logback-HtmlToConsole.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-HtmlToConsole.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/conf/logback-MDC.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-MDC.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/conf/logback-RollingSizeBased.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-RollingSizeBased.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/conf/logback-RollingTimeBased.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-RollingTimeBased.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/conf/logback-SMTP.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-SMTP.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/conf/logback-SMTPWithHtml.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/conf/logback-SMTPWithHtml.xml	Mon Sep 25 17:01:50 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-classic/examples/src/chapter4/sub/sample/Bar.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/examples/src/chapter4/sub/sample/Bar.java	Mon Sep 25 17:01:50 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"));
+  }
+}



More information about the logback-dev mailing list