[logback-dev] svn commit: r597 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/helpers logback-classic/src/main/java/ch/qos/logback/classic/html logback-classic/src/test/java/ch/qos/logback/classic/html logback-core/src/main/java/ch/qos/logback/core/helpers logback-core/src/main/java/ch/qos/logback/core/html
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Sep 21 15:57:39 CEST 2006
Author: seb
Date: Thu Sep 21 15:57:39 2006
New Revision: 597
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/CssBuilder.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/
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/IThrowableRenderer.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/NOPThrowableRenderer.java
Removed:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/CssBuilder.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/IThrowableRenderer.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/NOPThrowableRenderer.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/DefaultThrowableRenderer.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/HTMLLayout.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
Log:
- created HTMLLayoutBase
- updated HTMLLayout accordingly
- moved some classes to core module when appropriate.
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/DefaultThrowableRenderer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/DefaultThrowableRenderer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/html/DefaultThrowableRenderer.java Thu Sep 21 15:57:39 2006
@@ -4,6 +4,7 @@
import ch.qos.logback.classic.helpers.Transform;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.spi.ThrowableInformation;
+import ch.qos.logback.core.html.IThrowableRenderer;
public class DefaultThrowableRenderer implements IThrowableRenderer {
@@ -37,7 +38,8 @@
}
}
- public void render(StringBuffer sbuf, LoggingEvent event) {
+ public void render(StringBuffer sbuf, Object eventObject) {
+ LoggingEvent event = (LoggingEvent)eventObject;
ThrowableInformation ti = event.getThrowableInformation();
if (ti != null) {
render(sbuf, ti.getThrowableStrRep());
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 Thu Sep 21 15:57:39 2006
@@ -10,16 +10,13 @@
package ch.qos.logback.classic.html;
+import java.util.Map;
+
import ch.qos.logback.classic.ClassicLayout;
import ch.qos.logback.classic.PatternLayout;
-import ch.qos.logback.classic.helpers.CssBuilder;
import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.LayoutBase;
+import ch.qos.logback.core.html.HTMLLayoutBase;
import ch.qos.logback.core.pattern.Converter;
-import ch.qos.logback.core.pattern.DynamicConverter;
-import ch.qos.logback.core.pattern.parser.Node;
-import ch.qos.logback.core.pattern.parser.Parser;
-import ch.qos.logback.core.pattern.parser.ScanException;
/**
*
@@ -83,7 +80,7 @@
* @author Ceki Gülcü
* @author Sébastien Pennec
*/
-public class HTMLLayout extends LayoutBase implements ClassicLayout {
+public class HTMLLayout extends HTMLLayoutBase implements ClassicLayout {
/**
* Default pattern string for log output. Currently set to the string <b>"%m"
@@ -91,21 +88,6 @@
*/
static final String DEFAULT_CONVERSION_PATTERN = "%date%thread%level%logger%mdc%msg";
- private String pattern;
-
- private Converter head;
-
- private String title = "Logback Log Messages";
-
- private CssBuilder cssBuilder;
-
- IThrowableRenderer throwableRenderer = new DefaultThrowableRenderer();
-
- // counter keeping track of the rows output
- private long counter = 0;
- // max number of rows before we close the table and create a new one
- private static final int ROW_LIMIT = 10000;
-
/**
* Constructs a PatternLayout using the DEFAULT_LAYOUT_PATTERN.
*
@@ -114,167 +96,9 @@
public HTMLLayout() {
pattern = DEFAULT_CONVERSION_PATTERN;
}
-
- /**
- * Set the <b>ConversionPattern </b> option. This is the string which controls
- * formatting and consists of a mix of literal content and conversion
- * specifiers.
- */
- public void setPattern(String conversionPattern) {
- pattern = conversionPattern;
- }
-
- /**
- * Returns the value of the <b>ConversionPattern </b> option.
- */
- public String getPattern() {
- return pattern;
- }
-
- public CssBuilder getCssBuilder() {
- return cssBuilder;
- }
-
- public void setCssBuilder(CssBuilder cssBuilder) {
- this.cssBuilder = cssBuilder;
- }
-
- /**
- * Parses the pattern and creates the Converter linked list.
- */
- @Override
- public void start() {
- int errorCount = 0;
-
- if (throwableRenderer == null) {
- addError("ThrowableRender cannot be null.");
- errorCount++;
- }
-
- try {
- Parser p = new Parser(pattern);
- if (getContext() != null) {
- p.setStatusManager(getContext().getStatusManager());
- }
- Node t = p.parse();
- this.head = p.compile(t, PatternLayout.defaultConverterMap);
- DynamicConverter.startConverters(this.head);
- } catch (ScanException ex) {
- addError("Incorrect pattern found", ex);
- errorCount++;
- }
-
- if (errorCount == 0) {
- started = true;
- }
- }
-
- /**
- * The <b>Title </b> option takes a String value. This option sets the
- * document title of the generated HTML document.
- *
- * <p>
- * Defaults to 'Logback Log Messages'.
- */
- public void setTitle(String title) {
- this.title = title;
- }
-
- /**
- * Returns the current value of the <b>Title </b> option.
- */
- public String getTitle() {
- return title;
- }
-
- /**
- * Returns the content type output by this layout, i.e "text/html".
- */
- @Override
- public String getContentType() {
- return "text/html";
- }
-
- /**
- * Returns appropriate HTML headers.
- */
- @Override
- public String getHeader() {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
- sbuf.append(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
- sbuf.append(LINE_SEP);
- sbuf.append("<html>");
- sbuf.append(LINE_SEP);
- sbuf.append("<head>");
- sbuf.append(LINE_SEP);
- sbuf.append("<title>");
- sbuf.append(title);
- sbuf.append("</title>");
- sbuf.append(LINE_SEP);
- if (cssBuilder == null) {
- CssBuilder.addDefaultCSS(sbuf);
- } else {
- cssBuilder.addExternalCSS(sbuf);
- }
- sbuf.append(LINE_SEP);
- sbuf.append("</head>");
- sbuf.append(LINE_SEP);
- sbuf.append("<body>");
- sbuf.append(LINE_SEP);
-
- sbuf.append("<hr size=\"1\" noshade=\"true\" />");
- sbuf.append(LINE_SEP);
-
- sbuf.append("Log session start time ");
- sbuf.append(new java.util.Date());
- sbuf.append("<br />");
- sbuf.append(LINE_SEP);
- sbuf.append("<br />");
- sbuf.append(LINE_SEP);
- sbuf.append("<table cellspacing=\"0\">");
- sbuf.append(LINE_SEP);
-
- createTableHeader(sbuf);
-
- return sbuf.toString();
- }
-
- private void createTableHeader(StringBuffer sbuf) {
- Converter c = head;
- String name;
- sbuf.append("<tr class=\"header\">");
- sbuf.append(LINE_SEP);
- while (c != null) {
- name = computeConverterName(c);
- if (name == null) {
- c = c.getNext();
- continue;
- }
- sbuf.append("<td class=\"");
- sbuf.append(computeConverterName(c));
- sbuf.append("\">");
- sbuf.append(computeConverterName(c));
- sbuf.append("</td>");
- sbuf.append(LINE_SEP);
- c = c.getNext();
- }
- sbuf.append("</tr>");
- sbuf.append(LINE_SEP);
- }
-
- /**
- * Returns the appropriate HTML footers.
- */
- @Override
- public String getFooter() {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append("</table>");
- sbuf.append(LINE_SEP);
- sbuf.append("<br>");
- sbuf.append(LINE_SEP);
- sbuf.append("</body></html>");
- return sbuf.toString();
+
+ protected Map<String, String> getDefaultConverterMap() {
+ return PatternLayout.defaultConverterMap;
}
public String doLayout(Object event) {
@@ -316,18 +140,6 @@
return buf.toString();
}
- private void handleTableClosing(StringBuffer sbuf) {
- if (this.counter >= ROW_LIMIT) {
- counter = 0;
- sbuf.append("</table>");
- sbuf.append(LINE_SEP);
- sbuf.append("<br />");
- sbuf.append("<table cellspacing=\"0\">");
- sbuf.append(LINE_SEP);
- createTableHeader(sbuf);
- }
- }
-
private void appendEventToBuffer(StringBuffer buf, Converter c,
LoggingEvent event) {
buf.append("<td class=\"");
@@ -337,24 +149,4 @@
buf.append("</td>");
buf.append(LINE_SEP);
}
-
- private String computeConverterName(Converter c) {
- String className = c.getClass().getSimpleName();
- int index = className.indexOf("Converter");
- if (index == -1) {
- return className;
- } else {
- return className.substring(0, index);
- }
- }
-
- public IThrowableRenderer getThrowableRenderer() {
- return throwableRenderer;
- }
-
- public void setThrowableRenderer(IThrowableRenderer throwableRenderer) {
- this.throwableRenderer = throwableRenderer;
- }
-
-
}
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 Thu Sep 21 15:57:39 2006
@@ -66,7 +66,7 @@
public void testAppendThrowable() throws Exception {
StringBuffer buf = new StringBuffer();
String[] strArray = { "test1", "test2" };
- DefaultThrowableRenderer renderer = (DefaultThrowableRenderer)layout.throwableRenderer;
+ DefaultThrowableRenderer renderer = (DefaultThrowableRenderer)layout.getThrowableRenderer();
renderer.render(buf, strArray);
System.out.println(buf.toString());
String[] result = buf.toString().split(HTMLLayout.LINE_SEP);
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/CssBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/CssBuilder.java Thu Sep 21 15:57:39 2006
@@ -0,0 +1,81 @@
+/**
+ * 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 ch.qos.logback.core.helpers;
+
+import static ch.qos.logback.core.Layout.LINE_SEP;
+
+/**
+ * This class helps the HTMLLayout build the CSS link.
+ * It either provides the HTMLLayout with a default css file,
+ * or builds the link to an external, user-specified, file.
+ *
+ * @author Sébastien Pennec
+ */
+public class CssBuilder {
+
+ String url;
+
+ public CssBuilder() {
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public void addExternalCSS(StringBuffer sbuf) {
+ sbuf.append("<LINK REL=StyleSheet HREF=\"");
+ sbuf.append(url);
+ sbuf.append("\" TITLE=\"Basic\" />");
+ }
+
+ public static void addDefaultCSS(StringBuffer buf) {
+ buf.append("<STYLE type=\"text/css\">");
+ buf.append(LINE_SEP);
+ buf.append("table { margin-left: 2em; margin-right: 2em; border-left: 2px solid #AAA; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TR.even { background: #FFFFFF; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TR.odd { background: #DADADA; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TR.warn TD.level, TR.error TD.level, TR.fatal TD.level {font-weight: bold; color: #FF4040 }");
+ buf.append(LINE_SEP);
+
+ buf.append("TD { padding-right: 1ex; padding-left: 1ex; border-right: 2px solid #AAA; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TD.Time, TD.Date { text-align: right; font-family: courier, monospace; font-size: smaller; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TD.Thread { text-align: left; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TD.Level { text-align: right; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TD.Logger { text-align: left; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TR.header { background: #9090FF; color: #FFF; font-weight: bold; font-size: larger; }");
+ buf.append(LINE_SEP);
+
+ buf.append("TD.Exception { background: #C0C0F0; font-family: courier, monospace;}");
+ buf.append(LINE_SEP);
+
+ buf.append("</STYLE>");
+ buf.append(LINE_SEP);
+ }
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java Thu Sep 21 15:57:39 2006
@@ -0,0 +1,232 @@
+package ch.qos.logback.core.html;
+
+import java.util.Map;
+
+import ch.qos.logback.core.LayoutBase;
+import ch.qos.logback.core.helpers.CssBuilder;
+import ch.qos.logback.core.pattern.Converter;
+import ch.qos.logback.core.pattern.DynamicConverter;
+import ch.qos.logback.core.pattern.parser.Node;
+import ch.qos.logback.core.pattern.parser.Parser;
+import ch.qos.logback.core.pattern.parser.ScanException;
+
+/**
+ * This class is a base class for logback component-specific HTMLLayout classes
+ *
+ * @author Sébastien Pennec
+ */
+public abstract class HTMLLayoutBase extends LayoutBase {
+
+ protected String pattern;
+
+ protected Converter head;
+
+ protected String title = "Logback Log Messages";
+
+ protected CssBuilder cssBuilder;
+
+ protected IThrowableRenderer throwableRenderer; //no more initialization ??????
+
+ // counter keeping track of the rows output
+ protected long counter = 0;
+ // max number of rows before we close the table and create a new one
+ protected static final int ROW_LIMIT = 10000;
+
+ /**
+ * Set the <b>ConversionPattern </b> option. This is the string which controls
+ * formatting and consists of a mix of literal content and conversion
+ * specifiers.
+ */
+ public void setPattern(String conversionPattern) {
+ pattern = conversionPattern;
+ }
+
+ /**
+ * Returns the value of the <b>ConversionPattern </b> option.
+ */
+ public String getPattern() {
+ return pattern;
+ }
+
+ public CssBuilder getCssBuilder() {
+ return cssBuilder;
+ }
+
+ public void setCssBuilder(CssBuilder cssBuilder) {
+ this.cssBuilder = cssBuilder;
+ }
+
+ /**
+ * Parses the pattern and creates the Converter linked list.
+ */
+ @Override
+ public void start() {
+ int errorCount = 0;
+
+ if (throwableRenderer == null) {
+ addError("ThrowableRender cannot be null.");
+ errorCount++;
+ }
+
+ try {
+ Parser p = new Parser(pattern);
+ if (getContext() != null) {
+ p.setStatusManager(getContext().getStatusManager());
+ }
+ Node t = p.parse();
+ this.head = p.compile(t, getDefaultConverterMap());
+ DynamicConverter.startConverters(this.head);
+ } catch (ScanException ex) {
+ addError("Incorrect pattern found", ex);
+ errorCount++;
+ }
+
+ if (errorCount == 0) {
+ started = true;
+ }
+ }
+
+ protected abstract Map<String, String> getDefaultConverterMap();
+
+ /**
+ * The <b>Title </b> option takes a String value. This option sets the
+ * document title of the generated HTML document.
+ *
+ * <p>
+ * Defaults to 'Logback Log Messages'.
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Returns the current value of the <b>Title </b> option.
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Returns the content type output by this layout, i.e "text/html".
+ */
+ @Override
+ public String getContentType() {
+ return "text/html";
+ }
+
+ /**
+ * Returns appropriate HTML headers.
+ */
+ @Override
+ public String getHeader() {
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
+ sbuf.append(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<html>");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<head>");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<title>");
+ sbuf.append(title);
+ sbuf.append("</title>");
+ sbuf.append(LINE_SEP);
+ if (cssBuilder == null) {
+ CssBuilder.addDefaultCSS(sbuf);
+ } else {
+ cssBuilder.addExternalCSS(sbuf);
+ }
+ sbuf.append(LINE_SEP);
+ sbuf.append("</head>");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<body>");
+ sbuf.append(LINE_SEP);
+
+ sbuf.append("<hr size=\"1\" noshade=\"true\" />");
+ sbuf.append(LINE_SEP);
+
+ sbuf.append("Log session start time ");
+ sbuf.append(new java.util.Date());
+ sbuf.append("<br />");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<br />");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<table cellspacing=\"0\">");
+ sbuf.append(LINE_SEP);
+
+ createTableHeader(sbuf);
+
+ return sbuf.toString();
+ }
+
+
+ private void createTableHeader(StringBuffer sbuf) {
+ Converter c = head;
+ String name;
+ sbuf.append("<tr class=\"header\">");
+ sbuf.append(LINE_SEP);
+ while (c != null) {
+ name = computeConverterName(c);
+ if (name == null) {
+ c = c.getNext();
+ continue;
+ }
+ sbuf.append("<td class=\"");
+ sbuf.append(computeConverterName(c));
+ sbuf.append("\">");
+ sbuf.append(computeConverterName(c));
+ sbuf.append("</td>");
+ sbuf.append(LINE_SEP);
+ c = c.getNext();
+ }
+ sbuf.append("</tr>");
+ sbuf.append(LINE_SEP);
+ }
+
+ /**
+ * Returns the appropriate HTML footers.
+ */
+ @Override
+ public String getFooter() {
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append("</table>");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<br>");
+ sbuf.append(LINE_SEP);
+ sbuf.append("</body></html>");
+ return sbuf.toString();
+ }
+
+ protected void handleTableClosing(StringBuffer sbuf) {
+ if (this.counter >= ROW_LIMIT) {
+ counter = 0;
+ sbuf.append("</table>");
+ sbuf.append(LINE_SEP);
+ sbuf.append("<br />");
+ sbuf.append("<table cellspacing=\"0\">");
+ sbuf.append(LINE_SEP);
+ createTableHeader(sbuf);
+ }
+ }
+
+ protected String computeConverterName(Converter c) {
+ String className = c.getClass().getSimpleName();
+ int index = className.indexOf("Converter");
+ if (index == -1) {
+ return className;
+ } else {
+ return className.substring(0, index);
+ }
+ }
+
+ public IThrowableRenderer getThrowableRenderer() {
+ return throwableRenderer;
+ }
+
+ public void setThrowableRenderer(IThrowableRenderer throwableRenderer) {
+ this.throwableRenderer = throwableRenderer;
+ }
+
+
+
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/IThrowableRenderer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/IThrowableRenderer.java Thu Sep 21 15:57:39 2006
@@ -0,0 +1,8 @@
+package ch.qos.logback.core.html;
+
+
+public interface IThrowableRenderer {
+
+ public void render(StringBuffer sbuf, Object event);
+
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/NOPThrowableRenderer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/NOPThrowableRenderer.java Thu Sep 21 15:57:39 2006
@@ -0,0 +1,12 @@
+package ch.qos.logback.core.html;
+
+import ch.qos.logback.core.html.IThrowableRenderer;
+
+
+public class NOPThrowableRenderer implements IThrowableRenderer {
+
+ public void render(StringBuffer sbuf, Object event) {
+ return;
+ }
+
+}
More information about the logback-dev
mailing list