[logback-dev] svn commit: r955 - in logback/trunk: logback-classic/src/test/java/ch/qos/logback/classic/html logback-core/src/main/java/ch/qos/logback/core logback-core/src/main/java/ch/qos/logback/core/html

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Nov 17 18:12:23 CET 2006


Author: seb
Date: Fri Nov 17 18:12:23 2006
New Revision: 955

Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java

Log:
added presentation header and footer to WriterAppender
Updated HTMLLayout test

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	Fri Nov 17 18:12:23 2006
@@ -58,6 +58,17 @@
     String header = layout.getFileHeader();
     //System.out.println(header);
 
+    Document doc = parseOutput(header + "</body></html>");
+    Element rootElement = doc.getRootElement();
+    assertNotNull(rootElement.element("body"));
+  }
+
+  public void testPresentationHeader() {
+    String header = layout.getFileHeader();
+    String presentationHeader = layout.getPresentationHeader();
+    header = header + presentationHeader;
+    //System.out.println(header);
+
     Document doc = parseOutput(header + "</table></body></html>");
     Element rootElement = doc.getRootElement();
     Element bodyElement = rootElement.element("body");
@@ -68,7 +79,7 @@
     assertEquals("Thread", elementList.get(1).getText());
     assertEquals("Message", elementList.get(2).getText());
   }
-
+  
   public void testAppendThrowable() throws Exception {
     StringBuffer buf = new StringBuffer();
     String[] strArray = { "test1", "test2" };
@@ -111,6 +122,7 @@
     String result = layout.doLayout(le);
 
     String stringToParse = layout.getFileHeader();
+    stringToParse = stringToParse + layout.getPresentationHeader();
     stringToParse += result;
     stringToParse += "</table></body></html>";
 

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java	Fri Nov 17 18:12:23 2006
@@ -210,6 +210,10 @@
       if ((h != null) && (this.writer != null)) {
         try {
           this.writer.write(h);
+          String ph = layout.getPresentationHeader();
+          if (ph != null) {
+            this.writer.write(ph);
+          }
           // append a line separator. This should be useful in most cases and should 
           // not hurt. 
           this.writer.write(Layout.LINE_SEP);
@@ -230,6 +234,10 @@
       if ((h != null) && (this.writer != null)) {
         try {
           this.writer.write(h);
+          String pf = layout.getPresentationFooter();
+          if (pf != null) {
+            this.writer.write(pf);
+          }
           // flushing is mandatory if the writer is not later closed.
           this.writer.flush();
         } catch (IOException ioe) {

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	Fri Nov 17 18:12:23 2006
@@ -145,9 +145,13 @@
     sbuf.append("<body>");
     sbuf.append(LINE_SEP);
 
+    return sbuf.toString();
+  }
+  
+  public String getPresentationHeader() {
+    StringBuffer sbuf = new StringBuffer();
     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 />");
@@ -158,7 +162,7 @@
     sbuf.append(LINE_SEP);
 
     createTableHeader(sbuf);
-
+    
     return sbuf.toString();
   }
 
@@ -185,6 +189,12 @@
     sbuf.append("</tr>");
     sbuf.append(LINE_SEP);
   }
+  
+  public String getPresentationFooter() {
+    StringBuffer sbuf = new StringBuffer();
+    sbuf.append("</table>");
+    return sbuf.toString();    
+  }
 
   /**
    * Returns the appropriate HTML footers.
@@ -192,9 +202,6 @@
   @Override
   public String getFileFooter() {
     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();



More information about the logback-dev mailing list