[logback-dev] svn commit: r1187 - in logback/trunk: logback-examples/src/main/java/chapter4 logback-examples/src/main/java/chapter5 logback-examples/src/main/java/chapter7 logback-site/src/site/xdocTemplates/manual
noreply.seb at qos.ch
noreply.seb at qos.ch
Wed Jan 10 10:46:47 CET 2007
Author: seb
Date: Wed Jan 10 10:46:46 2007
New Revision: 1187
Modified:
logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
logback/trunk/logback-examples/src/main/java/chapter4/IO.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/chapter7/SimpleMDC.java
logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
logback/trunk/logback-site/src/site/xdocTemplates/manual/layouts.xml
logback/trunk/logback-site/src/site/xdocTemplates/manual/mdc.xml
Log:
Updated example classes and doc ->Generics
Modified: logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java Wed Jan 10 10:46:46 2007
@@ -10,16 +10,17 @@
package chapter4;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.Layout;
-public class CountingConsoleAppender extends AppenderBase {
+public class CountingConsoleAppender extends AppenderBase<LoggingEvent> {
static int DEFAULT_LIMIT = 10;
int counter = 0;
int limit = DEFAULT_LIMIT;
- private Layout layout;
+ private Layout<LoggingEvent> layout;
public CountingConsoleAppender() {
}
@@ -42,24 +43,24 @@
super.start();
}
- public void append(Object eventObject) {
+ public void append(LoggingEvent event) {
if (counter >= limit) {
return;
}
// output the events as formatted by our layout
- System.out.print(this.layout.doLayout(eventObject));
+ System.out.print(this.layout.doLayout(event));
// prepare for next event
counter++;
}
- public Layout getLayout() {
+ public Layout<LoggingEvent> getLayout() {
return layout;
}
- public void setLayout(Layout layout) {
+ public void setLayout(Layout<LoggingEvent> layout) {
this.layout = layout;
}
}
Modified: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java Wed Jan 10 10:46:46 2007
@@ -17,6 +17,7 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.WriterAppender;
import ch.qos.logback.core.layout.EchoLayout;
@@ -25,9 +26,9 @@
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.shutdownAndReset();//this is to cancel default-config.
- WriterAppender writerAppender = new WriterAppender();
+ WriterAppender<LoggingEvent> writerAppender = new WriterAppender<LoggingEvent>();
writerAppender.setContext(lc);
- writerAppender.setLayout(new EchoLayout());
+ writerAppender.setLayout(new EchoLayout<LoggingEvent>());
OutputStream os = new FileOutputStream("exitWoes1.log");
writerAppender.setWriter(new OutputStreamWriter(os));
Modified: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java Wed Jan 10 10:46:46 2007
@@ -17,6 +17,7 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.WriterAppender;
import ch.qos.logback.core.layout.EchoLayout;
import ch.qos.logback.core.util.StatusPrinter;
@@ -26,9 +27,9 @@
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.shutdownAndReset();//this is to cancel default-config.
- WriterAppender writerAppender = new WriterAppender();
+ WriterAppender<LoggingEvent> writerAppender = new WriterAppender<LoggingEvent>();
writerAppender.setContext(lc);
- writerAppender.setLayout(new EchoLayout());
+ writerAppender.setLayout(new EchoLayout<LoggingEvent>());
OutputStream os = new FileOutputStream("exitWoes2.log");
writerAppender.setWriter(new OutputStreamWriter(os));
Modified: logback/trunk/logback-examples/src/main/java/chapter4/IO.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/IO.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/IO.java Wed Jan 10 10:46:46 2007
@@ -14,6 +14,7 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.layout.EchoLayout;
@@ -40,14 +41,14 @@
// A FileAppender is created according to the buffering and
// immediate flush setting of this IO instance.
- FileAppender fa = new FileAppender();
+ FileAppender<LoggingEvent> fa = new FileAppender<LoggingEvent>();
if (longMessage) {
PatternLayout pa = new PatternLayout();
pa.setPattern("%r %5p %c [%t] - %m%n");
fa.setLayout(pa);
} else {
- fa.setLayout(new EchoLayout());
+ fa.setLayout(new EchoLayout<LoggingEvent>());
}
fa.setFile(getName() + ".log");
Modified: logback/trunk/logback-examples/src/main/java/chapter5/MySampleConverter.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/MySampleConverter.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/MySampleConverter.java Wed Jan 10 10:46:46 2007
@@ -12,8 +12,7 @@
private static final String WARN_COLOR = "\u001b[0;33m";
@Override
- public String convert(Object eventObject) {
- LoggingEvent event = (LoggingEvent) eventObject;
+ public String convert(LoggingEvent event) {
StringBuffer sbuf = new StringBuffer();
sbuf.append(getColor(event.getLevel()));
sbuf.append(event.getLevel());
Modified: logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout.java Wed Jan 10 10:46:46 2007
@@ -1,10 +1,9 @@
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<LoggingEvent> implements ClassicLayout {
+public class MySampleLayout extends LayoutBase<LoggingEvent> {
public String doLayout(LoggingEvent event) {
StringBuffer sbuf = new StringBuffer(128);
Modified: logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout2.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout2.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/MySampleLayout2.java Wed Jan 10 10:46:46 2007
@@ -1,10 +1,9 @@
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<LoggingEvent> implements ClassicLayout {
+public class MySampleLayout2 extends LayoutBase<LoggingEvent> {
String prefix = null;
boolean printThreadName = true;
Modified: logback/trunk/logback-examples/src/main/java/chapter5/PatternSample.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter5/PatternSample.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter5/PatternSample.java Wed Jan 10 10:46:46 2007
@@ -4,6 +4,7 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
public class PatternSample {
@@ -15,7 +16,7 @@
layout.setPattern("%-5level [%thread]: %message%n");
layout.start();
- ConsoleAppender appender = new ConsoleAppender();
+ ConsoleAppender<LoggingEvent> appender = new ConsoleAppender<LoggingEvent>();
appender.setContext(rootLogger.getLoggerContext());
appender.setLayout(layout);
appender.start();
Modified: logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter7/SimpleMDC.java Wed Jan 10 10:46:46 2007
@@ -15,6 +15,7 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
public class SimpleMDC {
@@ -27,7 +28,7 @@
PatternLayout layout = new PatternLayout();
layout.setPattern("%X{first} %X{last} - %m%n");
layout.start();
- ConsoleAppender appender = new ConsoleAppender();
+ ConsoleAppender<LoggingEvent> appender = new ConsoleAppender<LoggingEvent>();
appender.setLayout(layout);
appender.start();
Logger root = (Logger)LoggerFactory.getLogger("root");
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 Wed Jan 10 10:46:46 2007
@@ -298,9 +298,9 @@
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- WriterAppender writerAppender = new WriterAppender();
+ WriterAppender<LoggingEvent> writerAppender = new WriterAppender<LoggingEvent>();
writerAppender.setContext(lc);
- writerAppender.setLayout(new EchoLayout());
+ writerAppender.setLayout(new EchoLayout<LoggingEvent>());
OutputStream os = new FileOutputStream("exitWoes1.log");
writerAppender.setWriter(new OutputStreamWriter(os));
@@ -2664,12 +2664,12 @@
import ch.qos.logback.core.Layout;
-public class CountingConsoleAppender extends AppenderBase {
+public class CountingConsoleAppender extends AppenderBase<LoggingEvent> {
static int DEFAULT_LIMIT = 16;
int counter = 0;
int limit = DEFAULT_LIMIT;
- private Layout layout;
+ private Layout<LoggingEvent> layout;
public CountingConsoleAppender() {
}
@@ -2692,24 +2692,24 @@
super.start();
}
- public void append(Object eventObject) {
+ public void append(LoggingEvent event) {
if (counter >= limit) {
return;
}
// output the events as formatted by our layout
- System.out.print(this.layout.doLayout(eventObject));
+ System.out.print(this.layout.doLayout(event));
// prepare for next event
counter++;
}
- public Layout getLayout() {
+ public Layout<LoggingEvent> getLayout() {
return layout;
}
- public void setLayout(Layout layout) {
+ public void setLayout(Layout<LoggingEvent> layout) {
this.layout = layout;
}
}</pre></div>
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/layouts.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/layouts.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/layouts.xml Wed Jan 10 10:46:46 2007
@@ -89,17 +89,7 @@
Logback classic only processes events of type
<a href="../xref/ch/qos/logback/classic/spi/LoggingEvent.html">
<code>ch.qos.logback.classic.spi.LoggingEvent</code></a>.
- Therefore, logback classic module imposes that
- all its layouts implement
- the <a href="../xref/ch/qos/logback/classic/ClassicLayout.html"><code>ClassicLayout</code>
- </a> interface that is shown below.
- </p>
-
- <div class="source"><pre>public interface ClassicLayout extends Layout {
-
- String doLayout(LoggingEvent event);
-
-}</pre></div>
+ </p>
<h3>Writing your own Layout</h3>
<p>
@@ -118,11 +108,10 @@
(logback-examples/src/main/java/chapter5/MySampleLayout.java)</a></em>
<div class="source"><pre>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<LoggingEvent> implements ClassicLayout {
+public class MySampleLayout extends LayoutBase<LoggingEvent> {
public String doLayout(LoggingEvent event) {
StringBuffer sbuf = new StringBuffer(128);
@@ -154,10 +143,6 @@
have to handle, by adding <em><LoggingEvent></em> after its declaration.
</p>
- <p><code>MySampleLayout</code> implements the <code>ClassicLayout</code>
- interface, since it is intented to be used with the classic module.
- </p>
-
<p>The marginally more interesting <code>doLayout(LoggingEvent event)</code>
method begins by instantiating a StringBuffer. It proceeds by adding various
fields of the event parameter. The Texan from Texas was careful to print
@@ -232,11 +217,10 @@
<p>Here is the implementation of this class:</p>
<div class="source"><pre>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<LoggingEvent> implements ClassicLayout {
+public class MySampleLayout2 extends LayoutBase<LoggingEvent> {
String prefix = null;
boolean printThreadName = true;
@@ -305,8 +289,7 @@
<p>
Logback classic ships with a flexible layout called
<a href="../xref/ch/qos/logback/classic/PatternLayout.html">
- <code>PatternLayout</code></a>, which implements the
- <code>ClassicLayout</code> interface.
+ <code>PatternLayout</code></a>.
As all classic layouts, <code>PatternLayout</code>
takes a logging event and returns a String. However, the
returned String can be customized at will by tweaking its
@@ -351,7 +334,7 @@
layout.setPattern("%-5level [%thread]: %message%n");
layout.start();</b>
- ConsoleAppender appender = new ConsoleAppender();
+ ConsoleAppender<LoggingEvent> appender = new ConsoleAppender<LoggingEvent>();
appender.setContext(rootLogger.getLoggerContext());
appender.setLayout(layout); appender.start();
@@ -1237,8 +1220,7 @@
private static final String WARN_COLOR = "\u001b[0;33m";
@Override
- <b>public String convert(Object eventObject) {
- LoggingEvent event = (LoggingEvent) eventObject;
+ <b>public String convert(LoggingEvent event) {
StringBuffer sbuf = new StringBuffer();
sbuf.append(getColor(event.getLevel()));
sbuf.append(event.getLevel());
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/mdc.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/mdc.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/mdc.xml Wed Jan 10 10:46:46 2007
@@ -134,7 +134,7 @@
PatternLayout layout = new PatternLayout();
layout.setPattern("%X{first} %X{last} - %m%n");
layout.start();
- ConsoleAppender appender = new ConsoleAppender();
+ ConsoleAppender<LoggingEvent> appender = new ConsoleAppender<LoggingEvent>();
appender.setLayout(layout);
appender.start();
Logger root = (Logger)LoggerFactory.getLogger("root");
More information about the logback-dev
mailing list