[logback-dev] svn commit: r2106 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/html logback-classic/src/main/java/ch/qos/logback/classic logback-classic/src/main/java/ch/qos/logback/classic/html logback-classic/src/test/input/joran logback-classic/src/test/input/joran/conversionRule logback-classic/src/test/java/ch/qos/logback/classic logback-classic/src/test/java/ch/qos/logback/classic/html logback-classic/src/test/java/ch/qos/logback/classic/joran logback-classic/src/test/java/ch/qos/logback/classic/testUtil logback-core/src/main/java/ch/qos/logback/core/html logback-core/src/main/java/ch/qos/logback/core/joran/action logback-core/src/main/java/ch/qos/logback/core/pattern logback-examples/src/main/java/chapter6
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Sun Dec 28 20:31:50 CET 2008
Author: ceki
Date: Sun Dec 28 20:31:49 2008
New Revision: 2106
Added:
logback/trunk/logback-classic/src/test/input/joran/conversionRule/
logback/trunk/logback-classic/src/test/input/joran/conversionRule/htmlLayout0.xml
logback/trunk/logback-classic/src/test/input/joran/conversionRule/patternLayout0.xml
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/SampleConverter.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/StringListAppender.java
- copied, changed from r2086, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/StringListAppender.java
Removed:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/StringListAppender.java
Modified:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/HTMLLayout.java
logback/trunk/logback-classic/src/test/input/joran/callerData.xml
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java
logback/trunk/logback-examples/src/main/java/chapter6/GoMDC.java
Log:
- Fix LBCORE-74
HTMLLayoutBase now takes into custom conversion words.
- Moved StringListAppender to c.q.l.classic.testUtil package
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/html/HTMLLayout.java Sun Dec 28 20:31:49 2008
@@ -10,14 +10,14 @@
package ch.qos.logback.access.html;
+import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
+
import java.util.Map;
import ch.qos.logback.access.PatternLayout;
import ch.qos.logback.access.spi.AccessEvent;
import ch.qos.logback.core.html.HTMLLayoutBase;
-import ch.qos.logback.core.html.NOPThrowableRenderer;
import ch.qos.logback.core.pattern.Converter;
-import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
/**
*
@@ -47,7 +47,6 @@
*/
public HTMLLayout() {
pattern = DEFAULT_CONVERSION_PATTERN;
- throwableRenderer = new NOPThrowableRenderer();
cssBuilder = new DefaultCssBuilder();
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java Sun Dec 28 20:31:49 2008
@@ -50,8 +50,6 @@
public class PatternLayout extends PatternLayoutBase<LoggingEvent> {
- // FIXME fix exception handling
-
public static final Map<String, String> defaultConverterMap = new HashMap<String, String>();
static {
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/HTMLLayout.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/HTMLLayout.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/HTMLLayout.java Sun Dec 28 20:31:49 2008
@@ -16,30 +16,31 @@
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.html.DefaultCssBuilder;
import ch.qos.logback.core.html.HTMLLayoutBase;
+import ch.qos.logback.core.html.IThrowableRenderer;
import ch.qos.logback.core.pattern.Converter;
import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
/**
*
- * HTMLLayout outputs events in an HTML table.
- * <p>
- * The content of the table columns are specified using a conversion pattern.
- * See {@link ch.qos.logback.classic.PatternLayout} for documentation on the
- * available patterns.
- * <p>
- * For more information about this layout, please refer to the online manual at
+ * HTMLLayout outputs events in an HTML table. <p> The content of the table
+ * columns are specified using a conversion pattern. See
+ * {@link ch.qos.logback.classic.PatternLayout} for documentation on the
+ * available patterns. <p> For more information about this layout, please refer
+ * to the online manual at
* http://logback.qos.ch/manual/layouts.html#ClassicHTMLLayout
*
* @author Ceki Gülcü
* @author Sébastien Pennec
*/
public class HTMLLayout extends HTMLLayoutBase<LoggingEvent> {
-
+
/**
* Default pattern string for log output.
*/
static final String DEFAULT_CONVERSION_PATTERN = "%date%thread%level%logger%mdc%msg";
+ IThrowableRenderer throwableRenderer;
+
/**
* Constructs a PatternLayout using the DEFAULT_LAYOUT_PATTERN.
*
@@ -50,7 +51,19 @@
throwableRenderer = new DefaultThrowableRenderer();
cssBuilder = new DefaultCssBuilder();
}
-
+
+ @Override
+ public void start() {
+ int errorCount = 0;
+ if (throwableRenderer == null) {
+ addError("ThrowableRender cannot be null.");
+ errorCount++;
+ }
+ if (errorCount == 0) {
+ super.start();
+ }
+ }
+
protected Map<String, String> getDefaultConverterMap() {
return PatternLayout.defaultConverterMap;
}
@@ -90,8 +103,8 @@
return buf.toString();
}
- private void appendEventToBuffer(StringBuilder buf, Converter<LoggingEvent> c,
- LoggingEvent event) {
+ private void appendEventToBuffer(StringBuilder buf,
+ Converter<LoggingEvent> c, LoggingEvent event) {
buf.append("<td class=\"");
buf.append(computeConverterName(c));
buf.append("\">");
@@ -99,4 +112,12 @@
buf.append("</td>");
buf.append(LINE_SEPARATOR);
}
+
+ public IThrowableRenderer getThrowableRenderer() {
+ return throwableRenderer;
+ }
+
+ public void setThrowableRenderer(IThrowableRenderer throwableRenderer) {
+ this.throwableRenderer = throwableRenderer;
+ }
}
Modified: logback/trunk/logback-classic/src/test/input/joran/callerData.xml
==============================================================================
--- logback/trunk/logback-classic/src/test/input/joran/callerData.xml (original)
+++ logback/trunk/logback-classic/src/test/input/joran/callerData.xml Sun Dec 28 20:31:49 2008
@@ -12,7 +12,7 @@
</matcher>
</evaluator>
- <appender name="STR_LIST" class="ch.qos.logback.classic.StringListAppender">
+ <appender name="STR_LIST" class="ch.qos.logback.classic.testUtil.StringListAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%caller{4, helloEval}%d %level - %m%n</Pattern>
</layout>
Added: logback/trunk/logback-classic/src/test/input/joran/conversionRule/htmlLayout0.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/joran/conversionRule/htmlLayout0.xml Sun Dec 28 20:31:49 2008
@@ -0,0 +1,15 @@
+<configuration>
+
+ <conversionRule conversionWord="sample"
+ converterClass="ch.qos.logback.classic.testUtil.SampleConverter" />
+
+ <appender name="LIST" class="ch.qos.logback.classic.testUtil.StringListAppender">
+ <layout class="ch.qos.logback.classic.html.HTMLLayout">
+ <Pattern>%sample%msg</Pattern>
+ </layout>
+ </appender>
+
+ <root level="debug">
+ <appender-ref ref="LIST" />
+ </root>
+</configuration>
\ No newline at end of file
Added: logback/trunk/logback-classic/src/test/input/joran/conversionRule/patternLayout0.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/joran/conversionRule/patternLayout0.xml Sun Dec 28 20:31:49 2008
@@ -0,0 +1,15 @@
+<configuration>
+
+ <conversionRule conversionWord="sample"
+ converterClass="ch.qos.logback.classic.testUtil.SampleConverter" />
+
+ <appender name="LIST" class="ch.qos.logback.classic.testUtil.StringListAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%sample - %msg</Pattern>
+ </layout>
+ </appender>
+
+ <root level="debug">
+ <appender-ref ref="LIST" />
+ </root>
+</configuration>
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java Sun Dec 28 20:31:49 2008
@@ -1,17 +1,18 @@
/**
- * 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.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.classic;
import static ch.qos.logback.classic.TestConstants.ISO_REGEX;
import static ch.qos.logback.classic.TestConstants.MAIN_REGEX;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
@@ -20,18 +21,24 @@
import org.junit.Before;
import org.junit.Test;
+import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.pattern.ConverterTest;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.classic.testUtil.SampleConverter;
+import ch.qos.logback.classic.testUtil.StringListAppender;
+import ch.qos.logback.classic.util.TeztConstants;
import ch.qos.logback.core.Context;
+import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.pattern.PatternLayoutBase;
import ch.qos.logback.core.pattern.parser.AbstractPatternLayoutBaseTest;
public class PatternLayoutTest extends AbstractPatternLayoutBaseTest {
-
private PatternLayout pl = new PatternLayout();
private LoggerContext lc = new LoggerContext();
Logger logger = lc.getLogger(ConverterTest.class);
+ Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
+
LoggingEvent le;
List optionList = new ArrayList();
@@ -40,22 +47,23 @@
Exception ex = new Exception("Bogus exception");
le = makeLoggingEvent(ex);
}
-
+
@Before
public void setUp() {
pl.setContext(lc);
}
LoggingEvent makeLoggingEvent(Exception ex) {
- return new LoggingEvent(ch.qos.logback.core.pattern.FormattingConverter.class
- .getName(), logger, Level.INFO, "Some message", ex, null);
+ return new LoggingEvent(
+ ch.qos.logback.core.pattern.FormattingConverter.class.getName(),
+ logger, Level.INFO, "Some message", ex, null);
}
@Override
public LoggingEvent getEventObject() {
return makeLoggingEvent(null);
}
-
+
public PatternLayoutBase getPatternLayoutBase() {
return new PatternLayout();
}
@@ -65,8 +73,10 @@
pl.setPattern("%d %le [%t] %lo{30} - %m%n");
pl.start();
String val = pl.doLayout(getEventObject());
- // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some message
- String regex = ISO_REGEX+" INFO "+MAIN_REGEX+" c.q.l.c.pattern.ConverterTest - Some message\\s*";
+ // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some
+ // message
+ String regex = ISO_REGEX + " INFO " + MAIN_REGEX
+ + " c.q.l.c.pattern.ConverterTest - Some message\\s*";
assertTrue(val.matches(regex));
}
@@ -84,12 +94,13 @@
pl.setPattern("%-56(%d %lo{20}) - %m%n");
pl.start();
String val = pl.doLayout(getEventObject());
- // 2008-03-18 21:55:54,250 c.q.l.c.pattern.ConverterTest - Some message
- String regex = ISO_REGEX+" c.q.l.c.p.ConverterTest - Some message\\s*";
+ // 2008-03-18 21:55:54,250 c.q.l.c.pattern.ConverterTest - Some message
+ String regex = ISO_REGEX
+ + " c.q.l.c.p.ConverterTest - Some message\\s*";
assertTrue(val.matches(regex));
}
-
+
@Test
public void testNopExeptionHandler() {
pl.setPattern("%nopex %m%n");
@@ -97,25 +108,27 @@
String val = pl.doLayout(le);
assertTrue(!val.contains("java.lang.Exception: Bogus exception"));
}
-
+
@Test
public void testWithParenthesis() {
pl.setPattern("\\(%msg:%msg\\) %msg");
pl.start();
le = makeLoggingEvent(null);
String val = pl.doLayout(le);
- //System.out.println("VAL == " + val);
+ // System.out.println("VAL == " + val);
assertEquals("(Some message:Some message) Some message", val);
}
-
+
@Test
public void testWithLettersComingFromLog4j() {
- //Letters: p = level and c = logger
+ // Letters: p = level and c = logger
pl.setPattern("%d %p [%t] %c{30} - %m%n");
pl.start();
String val = pl.doLayout(getEventObject());
- // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some message
- String regex = TestConstants.ISO_REGEX+" INFO "+MAIN_REGEX+" c.q.l.c.pattern.ConverterTest - Some message\\s*";
+ // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some
+ // message
+ String regex = TestConstants.ISO_REGEX + " INFO " + MAIN_REGEX
+ + " c.q.l.c.pattern.ConverterTest - Some message\\s*";
assertTrue(val.matches(regex));
}
@@ -127,9 +140,27 @@
String val = pl.doLayout(getEventObject());
assertEquals("aValue", val);
}
-
+
@Override
public Context getContext() {
return lc;
}
+
+ void configure(String file) throws JoranException {
+ JoranConfigurator jc = new JoranConfigurator();
+ jc.setContext(lc);
+ jc.doConfigure(file);
+ }
+
+ @Test
+ public void testConversionRuleSupportInPatternLayout() throws JoranException {
+ configure(TeztConstants.TEST_DIR_PREFIX + "input/joran/conversionRule/patternLayout0.xml");
+ root.getAppender("LIST");
+ String msg = "Simon says";
+ logger.debug(msg);
+ StringListAppender sla = (StringListAppender) root.getAppender("LIST");
+ assertNotNull(sla);
+ assertEquals(1, sla.strList.size());
+ assertEquals(SampleConverter.SAMPLE_STR+" - "+msg, sla.strList.get(0));
+ }
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java Sun Dec 28 20:31:49 2008
@@ -1,6 +1,7 @@
package ch.qos.logback.classic.html;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -20,16 +21,20 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.TestConstants;
+import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.spi.ThrowableDataPoint;
import ch.qos.logback.classic.spi.ThrowableProxy;
+import ch.qos.logback.classic.testUtil.StringListAppender;
+import ch.qos.logback.classic.util.TeztConstants;
import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.read.ListAppender;
public class HTMLLayoutTest {
LoggerContext lc;
- Logger logger;
+ Logger root;
HTMLLayout layout;
@Before
@@ -45,8 +50,8 @@
layout.setPattern("%level%thread%msg");
layout.start();
appender.setLayout(layout);
- logger = lc.getLogger(LoggerContext.ROOT_NAME);
- logger.addAppender(appender);
+ root = lc.getLogger(LoggerContext.ROOT_NAME);
+ root.addAppender(appender);
appender.start();
}
@@ -89,7 +94,8 @@
@Test
public void testAppendThrowable() throws Exception {
StringBuilder buf = new StringBuilder();
- ThrowableDataPoint[] strArray = { new ThrowableDataPoint("test1"), new ThrowableDataPoint("test2") };
+ ThrowableDataPoint[] strArray = { new ThrowableDataPoint("test1"),
+ new ThrowableDataPoint("test2") };
DefaultThrowableRenderer renderer = (DefaultThrowableRenderer) layout
.getThrowableRenderer();
renderer.render(buf, strArray);
@@ -145,8 +151,7 @@
public void layoutWithException() throws Exception {
layout.setPattern("%level %thread %msg %ex");
LoggingEvent le = createLoggingEvent();
- le.setThrowableProxy(new ThrowableProxy(new Exception(
- "test Exception")));
+ le.setThrowableProxy(new ThrowableProxy(new Exception("test Exception")));
String result = layout.doLayout(le);
String stringToParse = layout.getFileHeader();
@@ -168,18 +173,19 @@
assertTrue(exceptionElement.getText().contains(
"java.lang.Exception: test Exception"));
}
-
+
@Test
@Ignore
public void rawLimit() throws Exception {
StringBuilder sb = new StringBuilder();
String header = layout.getFileHeader();
- assertTrue(header.startsWith("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"));
+ assertTrue(header
+ .startsWith("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"));
sb.append(header);
sb.append(layout.getPresentationHeader());
- for(int i = 0; i < CoreConstants.TABLE_ROW_LIMIT*3; i++) {
- sb.append(layout.doLayout( new LoggingEvent(this.getClass().getName(), logger,
- Level.DEBUG, "test message"+i, null, null)));
+ for (int i = 0; i < CoreConstants.TABLE_ROW_LIMIT * 3; i++) {
+ sb.append(layout.doLayout(new LoggingEvent(this.getClass().getName(),
+ root, Level.DEBUG, "test message" + i, null, null)));
}
sb.append(layout.getPresentationFooter());
sb.append(layout.getFileFooter());
@@ -188,7 +194,7 @@
}
private LoggingEvent createLoggingEvent() {
- LoggingEvent le = new LoggingEvent(this.getClass().getName(), logger,
+ LoggingEvent le = new LoggingEvent(this.getClass().getName(), root,
Level.DEBUG, "test message", null, null);
return le;
}
@@ -200,4 +206,23 @@
reader.setEntityResolver(resolver);
return reader.read(new ByteArrayInputStream(output.getBytes()));
}
+
+ void configure(String file) throws JoranException {
+ JoranConfigurator jc = new JoranConfigurator();
+ jc.setContext(lc);
+ jc.doConfigure(file);
+ }
+
+ @Test
+ public void testConversionRuleSupportInHtmlLayout() throws JoranException {
+ configure(TeztConstants.TEST_DIR_PREFIX
+ + "input/joran/conversionRule/htmlLayout0.xml");
+ root.getAppender("LIST");
+ String msg = "Simon says";
+ root.debug(msg);
+ StringListAppender sla = (StringListAppender) root.getAppender("LIST");
+ assertNotNull(sla);
+ assertEquals(1, sla.strList.size());
+ assertFalse(sla.strList.get(0).contains("PARSER_ERROR"));
+ }
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java Sun Dec 28 20:31:49 2008
@@ -19,8 +19,8 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.StringListAppender;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.classic.testUtil.StringListAppender;
import ch.qos.logback.classic.turbo.DebugUsersTurboFilter;
import ch.qos.logback.classic.turbo.NOPTurboFilter;
import ch.qos.logback.classic.turbo.TurboFilter;
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/SampleConverter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/SampleConverter.java Sun Dec 28 20:31:49 2008
@@ -0,0 +1,24 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.testUtil;
+
+import ch.qos.logback.classic.pattern.ClassicConverter;
+import ch.qos.logback.classic.spi.LoggingEvent;
+
+public class SampleConverter extends ClassicConverter {
+
+ static public final String SAMPLE_STR = "sample";
+
+ @Override
+ public String convert(LoggingEvent event) {
+ return SAMPLE_STR;
+ }
+
+}
Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/StringListAppender.java (from r2086, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/StringListAppender.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/StringListAppender.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/testUtil/StringListAppender.java Sun Dec 28 20:31:49 2008
@@ -1,4 +1,4 @@
-package ch.qos.logback.classic;
+package ch.qos.logback.classic.testUtil;
import java.util.ArrayList;
import java.util.List;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java Sun Dec 28 20:31:49 2008
@@ -1,7 +1,18 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.core.html;
+import java.util.HashMap;
import java.util.Map;
+import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreConstants;
import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
import ch.qos.logback.core.LayoutBase;
@@ -12,7 +23,9 @@
import ch.qos.logback.core.pattern.parser.ScanException;
/**
- * This class is a base class for logback component-specific HTMLLayout classes
+ * This class is a base class for HTMLLayout classes part of
+ * other logback modules such as logback-classic and logback-access.
+ *
*
* @author Sébastien Pennec
*/
@@ -28,9 +41,7 @@
//this variable in their constructor to a default value.
protected CssBuilder cssBuilder;
- protected IThrowableRenderer throwableRenderer; //no more initialization ??????
-
- // counter keeping track of the rows output
+ // counter keeping track of the rows output
protected long counter = 0;
/**
@@ -64,16 +75,11 @@
public void start() {
int errorCount = 0;
- if (throwableRenderer == null) {
- addError("ThrowableRender cannot be null.");
- errorCount++;
- }
-
try {
Parser<E> p = new Parser<E>(pattern);
p.setContext(getContext());
Node t = p.parse();
- this.head = p.compile(t, getDefaultConverterMap());
+ this.head = p.compile(t, getEffectiveConverterMap());
ConverterUtil.startConverters(this.head);
} catch (ScanException ex) {
addError("Incorrect pattern found", ex);
@@ -87,6 +93,33 @@
protected abstract Map<String, String> getDefaultConverterMap();
+
+ /**
+ * Returns a map where the default converter map is merged with the map
+ * contained in the context.
+ */
+ public Map<String, String> getEffectiveConverterMap() {
+ Map<String, String> effectiveMap = new HashMap<String, String>();
+
+ // add the least specific map fist
+ Map<String, String> defaultMap = getDefaultConverterMap();
+ if (defaultMap != null) {
+ effectiveMap.putAll(defaultMap);
+ }
+
+ // contextMap is more specific than the default map
+ Context context = getContext();
+ if (context != null) {
+ @SuppressWarnings("unchecked")
+ Map<String, String> contextMap = (Map<String, String>) context
+ .getObject(CoreConstants.PATTERN_RULE_REGISTRY);
+ if (contextMap != null) {
+ effectiveMap.putAll(contextMap);
+ }
+ }
+ return effectiveMap;
+ }
+
/**
* The <b>Title </b> option takes a String value. This option sets the
* document title of the generated HTML document.
@@ -226,14 +259,4 @@
}
}
- public IThrowableRenderer getThrowableRenderer() {
- return throwableRenderer;
- }
-
- public void setThrowableRenderer(IThrowableRenderer throwableRenderer) {
- this.throwableRenderer = throwableRenderer;
- }
-
-
-
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java Sun Dec 28 20:31:49 2008
@@ -1,7 +1,7 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, 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
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java Sun Dec 28 20:31:49 2008
@@ -1,11 +1,11 @@
/**
- * 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.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.core.pattern;
@@ -22,15 +22,14 @@
import ch.qos.logback.core.status.ErrorStatus;
import ch.qos.logback.core.status.StatusManager;
-
abstract public class PatternLayoutBase<E> extends LayoutBase<E> {
Converter<E> head;
String pattern;
protected PostCompileProcessor<E> postCompileProcessor;
-
+
Map<String, String> instanceConverterMap = new HashMap<String, String>();
-
+
/**
* Concrete implementations of this class are responsible for elaborating the
* mapping between pattern words and converters.
@@ -43,30 +42,27 @@
* Returns a map where the default converter map is merged with the map
* contained in the context.
*/
- @SuppressWarnings("unchecked")
public Map<String, String> getEffectiveConverterMap() {
-
Map<String, String> effectiveMap = new HashMap<String, String>();
-
// add the least specific map fist
Map<String, String> defaultMap = getDefaultConverterMap();
if (defaultMap != null) {
effectiveMap.putAll(defaultMap);
}
-
+
// contextMap is more specific than the default map
Context context = getContext();
if (context != null) {
- Map<String, String> contextMap = (Map) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
+ @SuppressWarnings("unchecked")
+ Map<String, String> contextMap = (Map<String, String>) context
+ .getObject(CoreConstants.PATTERN_RULE_REGISTRY);
if (contextMap != null) {
effectiveMap.putAll(contextMap);
}
}
-
// set the most specific map last
effectiveMap.putAll(instanceConverterMap);
-
return effectiveMap;
}
@@ -78,7 +74,7 @@
}
Node t = p.parse();
this.head = p.compile(t, getEffectiveConverterMap());
- if(postCompileProcessor != null) {
+ if (postCompileProcessor != null) {
postCompileProcessor.process(head);
}
setContextForConverters(head);
@@ -95,7 +91,7 @@
PostCompileProcessor<E> postCompileProcessor) {
this.postCompileProcessor = postCompileProcessor;
}
-
+
protected void setContextForConverters(Converter<E> head) {
Context context = getContext();
Converter c = head;
Modified: logback/trunk/logback-examples/src/main/java/chapter6/GoMDC.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter6/GoMDC.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter6/GoMDC.java Sun Dec 28 20:31:49 2008
@@ -1,4 +1,4 @@
-package chapter5;
+package chapter6;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
More information about the logback-dev
mailing list