[logback-dev] svn commit: r766 - in logback/trunk/logback-core/src/main/java/ch/qos/logback/core: helpers html rolling

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Oct 24 20:50:35 CEST 2006


Author: seb
Date: Tue Oct 24 20:50:34 2006
New Revision: 766

Added:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/CssBuilder.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/DefaultCssBuilder.java
      - copied, changed from r764, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/DefaultCssBuilder.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/UrlCssBuilder.java
Removed:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/DefaultCssBuilder.java
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/rolling/RollingFileAppender.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java

Log:

-- refactoring of css builder
- started work on merging activeFileName and FileName 

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/CssBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/CssBuilder.java	Tue Oct 24 20:50:34 2006
@@ -0,0 +1,7 @@
+package ch.qos.logback.core.html;
+
+public interface CssBuilder {
+
+  public void addCss(StringBuffer sbuf);
+  
+}

Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/DefaultCssBuilder.java (from r764, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/DefaultCssBuilder.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/helpers/DefaultCssBuilder.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/DefaultCssBuilder.java	Tue Oct 24 20:50:34 2006
@@ -7,75 +7,65 @@
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation.
  */
-package ch.qos.logback.core.helpers;
+package ch.qos.logback.core.html;
 
 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.
- *
+ * 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 DefaultCssBuilder {
+public class DefaultCssBuilder implements CssBuilder {
 
-  String url;
-  
-  public DefaultCssBuilder() {  
+  public DefaultCssBuilder() {
   }
-  
-  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: #EAEAEA; }");
-    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: #596ED5; color: #FFF; font-weight: bold; font-size: larger; }");
-    buf.append(LINE_SEP);
 
-    buf.append("TD.Exception { background: #A2AEE8; font-family: courier, monospace;}");
-    buf.append(LINE_SEP);
+  public void addCss(StringBuffer sbuf) {
+    sbuf.append("<STYLE  type=\"text/css\">");
+    sbuf.append(LINE_SEP);
+    sbuf
+        .append("table { margin-left: 2em; margin-right: 2em; border-left: 2px solid #AAA; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf.append("TR.even { background: #FFFFFF; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf.append("TR.odd { background: #EAEAEA; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf
+        .append("TR.warn TD.Level, TR.error TD.Level, TR.fatal TD.Level {font-weight: bold; color: #FF4040 }");
+    sbuf.append(LINE_SEP);
+
+    sbuf
+        .append("TD { padding-right: 1ex; padding-left: 1ex; border-right: 2px solid #AAA; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf
+        .append("TD.Time, TD.Date { text-align: right; font-family: courier, monospace; font-size: smaller; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf.append("TD.Thread { text-align: left; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf.append("TD.Level { text-align: right; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf.append("TD.Logger { text-align: left; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf
+        .append("TR.header { background: #596ED5; color: #FFF; font-weight: bold; font-size: larger; }");
+    sbuf.append(LINE_SEP);
+
+    sbuf
+        .append("TD.Exception { background: #A2AEE8; font-family: courier, monospace;}");
+    sbuf.append(LINE_SEP);
 
-    buf.append("</STYLE>");
-    buf.append(LINE_SEP);
+    sbuf.append("</STYLE>");
+    sbuf.append(LINE_SEP);
   }
 }

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	Tue Oct 24 20:50:34 2006
@@ -3,7 +3,6 @@
 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;
@@ -23,6 +22,8 @@
 
   protected String title = "Logback Log Messages";
 
+  //It is the responsability of derived classes to set
+  //this variable in their constructor to a default value.
   protected CssBuilder cssBuilder;
 
   protected IThrowableRenderer throwableRenderer; //no more initialization ??????
@@ -131,11 +132,13 @@
     sbuf.append(title);
     sbuf.append("</title>");
     sbuf.append(LINE_SEP);
-    if (cssBuilder == null) {
-      CssBuilder.addDefaultCSS(sbuf);
-    } else {
-      cssBuilder.addExternalCSS(sbuf);
-    }
+    
+    cssBuilder.addCss(sbuf);
+//    if (cssBuilder == null) {
+//      DefaultCssBuilder.addDefaultCSS(sbuf);
+//    } else {
+//      cssBuilder.addExternalCSS(sbuf);
+//    }
     sbuf.append(LINE_SEP);
     sbuf.append("</head>");
     sbuf.append(LINE_SEP);

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/UrlCssBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/UrlCssBuilder.java	Tue Oct 24 20:50:34 2006
@@ -0,0 +1,40 @@
+/**
+ * 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.html;
+
+
+/**
+ * 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&eacute;bastien Pennec
+ */
+public class UrlCssBuilder implements CssBuilder {
+
+  String url = "http://logback.qos.ch/css/classic.css";
+  
+  public UrlCssBuilder() {  
+  }
+  
+  public String getUrl() {
+    return url;
+  }
+  
+  public void setUrl(String url) {
+    this.url = url;
+  }
+  
+  public void addCss(StringBuffer sbuf) {
+    sbuf.append("<LINK REL=StyleSheet HREF=\"");
+    sbuf.append(url);
+    sbuf.append("\" TITLE=\"Basic\" />");
+  }
+}

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java	Tue Oct 24 20:50:34 2006
@@ -83,8 +83,12 @@
       // the activeFile variable is used by the triggeringPolicy.isTriggeringEvent method
       activeFileCache = new File(afn);
       addInfo("Active log file name: "+afn);
-      setFile(afn);
 
+      // The local setFile throws an exception, so we use the parent's version.
+      // This is to prevent the user from configuring both the RollingFileAppender with
+      // an activeFileName _and_ the FileAppender's file attribute, causing confusion
+      // on the attributes' uses.
+      super.setFile(afn);
       super.start();
     } else {
       addWarn("No RollingPolicy was set for the RollingFileAppender named "+ getName());
@@ -185,4 +189,10 @@
       rollingPolicy = (RollingPolicy) policy;
     }
   }
+  
+  @Override
+  public void setFile(String filename) {
+    throw new UnsupportedOperationException("With RollingFileAppender please use activeFileName " +
+                                "option instead of File");
+  }
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java	Tue Oct 24 20:50:34 2006
@@ -26,6 +26,11 @@
   protected int compressionMode = Compress.NONE;
   protected FileNamePattern fileNamePattern;
   protected String fileNamePatternStr;
+  /*
+   * It would have been nice to merge 'activeFileName' into filename of
+   * FileAppender. Unfortunately, a child component must be self contained
+   * as it is started before its parent.
+   */
   protected String activeFileName = null;
 
   private boolean started;



More information about the logback-dev mailing list