[logback-dev] svn commit: r878 - in logback/trunk: logback-examples/src/main/java/chapter4 logback-site/src/site/xdocTemplates/manual

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Nov 7 09:31:30 CET 2006


Author: seb
Date: Tue Nov  7 09:31:30 2006
New Revision: 878

Added:
   logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java
      - copied, changed from r875, /logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java
   logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
Removed:
   logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java
Modified:
   logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml

Log:
one more example


Copied: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java (from r875, /logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java)
==============================================================================
--- /logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java	(original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java	Tue Nov  7 09:31:30 2006
@@ -20,10 +20,11 @@
 import ch.qos.logback.core.WriterAppender;
 import ch.qos.logback.core.layout.EchoLayout;
 
-public class ExitWoes {
+public class ExitWoes1 {
 
   public static void main(String[] args) throws Exception {
     LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+    lc.reset();//this is to cancel default-config.
     WriterAppender writerAppender = new WriterAppender();
     writerAppender.setContext(lc);
     writerAppender.setLayout(new EchoLayout());
@@ -33,7 +34,7 @@
     writerAppender.setImmediateFlush(false);
     writerAppender.start();
 
-    Logger logger = lc.getLogger(ExitWoes.class);
+    Logger logger = lc.getLogger(ExitWoes1.class);
 
     logger.debug("Hello world.");
   }

Added: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java	Tue Nov  7 09:31:30 2006
@@ -0,0 +1,43 @@
+/**
+ * Logback: the reliable, generic, 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 chapter4;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.WriterAppender;
+import ch.qos.logback.core.layout.EchoLayout;
+
+public class ExitWoes2 {
+
+  public static void main(String[] args) throws Exception {
+    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+    lc.reset();//this is to cancel default-config.
+    WriterAppender writerAppender = new WriterAppender();
+    writerAppender.setContext(lc);
+    writerAppender.setLayout(new EchoLayout());
+
+    OutputStream os = new FileOutputStream("exitWoes2.log");
+    writerAppender.setWriter(new OutputStreamWriter(os));
+    writerAppender.setImmediateFlush(false);
+    writerAppender.start();
+
+    Logger logger = lc.getLogger(ExitWoes2.class);
+
+    logger.debug("Hello world.");
+    
+    lc.reset();
+  }
+}
\ No newline at end of file

Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml	(original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml	Tue Nov  7 09:31:30 2006
@@ -269,7 +269,7 @@
 		will be lost as illustrated by the next example. 
 	</p>
 	
-	<em>Example 4.1: Exiting an application without flushing (<a href="../xref/chapter4/ExitWoes.html">logback-examples/src/main/java/chapter4/ExitWoes.java</a>)</em>
+	<em>Example 4.1: Exiting an application without flushing (<a href="../xref/chapter4/ExitWoes1.html">logback-examples/src/main/java/chapter4/ExitWoes1.java</a>)</em>
 <div class="source"><pre>package chapter4;
 
 import java.io.FileOutputStream;
@@ -283,7 +283,7 @@
 import ch.qos.logback.core.WriterAppender;
 import ch.qos.logback.core.layout.EchoLayout;
 
-public class ExitWoes {
+public class ExitWoes1 {
 
   public static void main(String[] args) throws Exception {
     LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
@@ -316,9 +316,9 @@
 		<em>exitWoes1.log</em>
 		because the Java VM does not flush output streams when it exits. 
 		Calling the <code>reset()</code> method of a <code>LoggerContext</code> ensures that all 
-		appenders in the hierarchy are closed and their buffers are flushed. 
-		For most applications this is as simple as including the following statement 
-		before exiting the application.
+		appenders in the hierarchy are closed and their buffers are flushed. The
+		<code>ExitWoes2</code> class uses this statement and outputs a logging
+		request. <b>DOES NOT WORK ??</b>
 	</p>
 
 	<p>
@@ -1609,6 +1609,13 @@
 }</pre></div>
 
 		<p>
+			Note that this implementation extends <code>TriggeringPolicyBase</code> instead
+			of implementing <code>TriggeringPolicy</code>. This allows the user to concentrate
+			on the core functions of her <code>TriggeringPolicy</code> and let the base class
+			manage the other functionnalities.
+		</p>
+
+		<p>
 			Setting the <span class="option">EvaluatorClass</span> option of 
 			<code>SMTPAppender</code> instructs it to use a custom evaluator. 
 			The next configuration file attaches a <code>SMTPAppender</code> to the root logger. 
@@ -1621,7 +1628,7 @@
 
 <div class="source"><pre>&lt;configuration>
   &lt;appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
-    &lt;EvaluatorClass>chapter4.mail.CounterBasedTP&lt;/EvaluatorClass>
+    <b>&lt;EvaluatorClass>chapter4.mail.CounterBasedTP&lt;/EvaluatorClass></b>
     &lt;BufferSize>1050&lt;/BufferSize>
     &lt;SMTPHost>${smtpHost}&lt;/SMTPHost>
     &lt;To>${to}&lt;/To>
@@ -1635,19 +1642,22 @@
   &lt;/root>  
 &lt;/configuration></pre></div>
 
+		<h3>DBAppender</h3>
+
+
 
 
 
 
 
 
-		<h3>DBAppender</h3>
-		<h3>SyslogAppender</h3>
 
 
 
 
 
+		<h3>SyslogAppender</h3>
+
 		<h2>Logback Access</h2>
 		
 		<h3>SMTPAppender</h3>



More information about the logback-dev mailing list