[LOGBack-dev] svn commit: r562 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/helpers main/java/ch/qos/logback/classic/html test/java/ch/qos/logback/classic/html
noreply.seb at qos.ch
noreply.seb at qos.ch
Tue Sep 12 15:22:21 CEST 2006
Author: seb
Date: Tue Sep 12 15:22:21 2006
New Revision: 562
Added:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/CssBuilder.java
Modified:
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:
- added a CssBuilder class that provides the HTMLLayout with either a default css file,
or builds the link to a user-specified external css file.
- updated test
Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/CssBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/CssBuilder.java Tue Sep 12 15:22:21 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.classic.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);
+ }
+}
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 Tue Sep 12 15:22:21 2006
@@ -12,6 +12,7 @@
import ch.qos.logback.classic.ClassicLayout;
import ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.classic.helpers.CssBuilder;
import ch.qos.logback.classic.helpers.Transform;
import ch.qos.logback.classic.pattern.ThrowableHandlingConverter;
import ch.qos.logback.classic.spi.LoggingEvent;
@@ -52,6 +53,7 @@
//private String timezone;
private String title = "Logback Log Messages";
+ private CssBuilder cssBuilder;
private boolean internalCSS = false;
private String url2ExternalCSS = "http://logging.apache.org/log4j/docs/css/eventTable-1.0.css";
@@ -87,6 +89,14 @@
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.
@@ -137,50 +147,6 @@
}
/**
- * Returns the value of the internalCSS option. See {@link #setInternalCSS}
- * method for details about the meaning of this option.
- *
- * @return boolean Value of internalCSS option
- */
- public boolean isInternalCSS() {
- return internalCSS;
- }
-
- /**
- * Set the value of the internalCSS option. If set to true, the generated HTML
- * ouput will include an internal cascading style sheet. Otherwise, the
- * generated HTML output will include a reference to an external CSS.
- * <p>
- * By default, <code>internalCSS</code> value is set to false, that is, by
- * default, only a link to an external CSS file will be generated.
- *
- * @see #setURL2ExternalCSS
- *
- * @param internalCSS
- */
- public void setInternalCSS(boolean internalCSS) {
- this.internalCSS = internalCSS;
- }
-
- /**
- * Return the URL to the external CSS file. See {@link #setURL2ExternalCSS}
- * method for details about the meaning of this option.
- *
- * @return URL to the external CSS file.
- */
- public String getURL2ExternalCSS() {
- return url2ExternalCSS;
- }
-
- /**
- * Set the URL for the external CSS file. By default, the external CSS file is
- * set to "http://logging.apache.org/log4j/docs/css/eventTable-1.0.css".
- */
- public void setURL2ExternalCSS(String url2ExternalCSS) {
- this.url2ExternalCSS = url2ExternalCSS;
- }
-
- /**
* Returns the content type output by this layout, i.e "text/html".
*/
public String getContentType() {
@@ -219,12 +185,10 @@
sbuf.append(title);
sbuf.append("</title>");
sbuf.append(LINE_SEP);
- if (internalCSS) {
- getInternalCSS(sbuf);
+ if (cssBuilder == null) {
+ CssBuilder.addDefaultCSS(sbuf);
} else {
- sbuf.append("<LINK REL=StyleSheet HREF=\"");
- sbuf.append(url2ExternalCSS);
- sbuf.append("\" TITLE=\"Basic\" />");
+ cssBuilder.addExternalCSS(sbuf);
}
sbuf.append(LINE_SEP);
sbuf.append("</head>");
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 Tue Sep 12 15:22:21 2006
@@ -32,7 +32,6 @@
layout = new HTMLLayout();
layout.setContext(lc);
layout.setPattern("%level %thread %msg");
- layout.setInternalCSS(true);
layout.start();
appender.setLayout(layout);
logger = lc.getLogger(LoggerContext.ROOT_NAME);
More information about the logback-dev
mailing list