You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by SD <lo...@fishh2o.com> on 2005/10/03 23:27:53 UTC

HTMLLayout.java Patch

Patch for HTMLLayout.java to allow the user of the logger to turn the 
html header/footer off if needed.

I'm using log4j to output some html but I'm doing this within an 
existing webpage.  Therefore, I don't need/want the html 
header/footer that the logger normally prints out.

Added the member var shouldWriteHtmlHeaderAndFooter and the 
appropriate if statements to make the desired effect.  Also added an 
assessor and setter for shouldWriteHtmlHeaderAndFooter.


Thanx for the awesome logging lib.



Index: HTMLLayout.java
===================================================================
RCS file: 
/home/cvspublic/logging-log4j/src/java/org/apache/log4j/html/HTMLLayout.java,v
retrieving revision 1.7
diff -u -r1.7 HTMLLayout.java
--- HTMLLayout.java	22 May 2005 07:56:22 -0000	1.7
+++ HTMLLayout.java	3 Oct 2005 20:42:58 -0000
@@ -66,6 +66,7 @@
    private FormattingInfo[] patternFields;
    private String timezone;
    private String title = "Log4J Log Messages";
+  private boolean shouldWriteHtmlHeaderAndFooter = true;

    private boolean internalCSS = false;
    private String url2ExternalCSS = 
"http://logging.apache.org/log4j/docs/css/eventTable-1.0.css";
@@ -109,6 +110,16 @@
    public String getConversionPattern() {
      return pattern;
    }
+ 
+  public boolean shouldWriteHtmlHeaderAndFooter()
+  {
+	return shouldWriteHtmlHeaderAndFooter;
+  }
+ 
+  public void setShouldWriteHtmlHeaderAndFooter(boolean 
shouldWriteHtmlHeaderAndFooter)
+  {
+	this.shouldWriteHtmlHeaderAndFooter = shouldWriteHtmlHeaderAndFooter;
+  }

    /**
     * Does not do anything as options become effective
@@ -236,28 +247,31 @@
     */
    public String getHeader() {
      StringBuffer sbuf = new StringBuffer();
-    sbuf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 
Transitional//EN\"");
-    sbuf.append(" \"http://www.w3.org/TR/html4/loose.dtd\">");
-    sbuf.append(Layout.LINE_SEP);
-    sbuf.append("<html>");
-    sbuf.append(Layout.LINE_SEP);
-    sbuf.append("<head>");
-    sbuf.append(Layout.LINE_SEP);
-    sbuf.append("<title>" + title + "</title>");
-    sbuf.append(Layout.LINE_SEP);
-    if(internalCSS) {
-      getInternalCSS(sbuf);
-    } else {
-      sbuf.append("<LINK REL=StyleSheet HREF=\""+url2ExternalCSS+"\" 
TITLE=\"Basic\">");
-    }
-    sbuf.append(Layout.LINE_SEP);
-    sbuf.append("</head>");
-    sbuf.append(Layout.LINE_SEP);
-    sbuf.append("<body>");
-    sbuf.append(Layout.LINE_SEP);
-   
-    sbuf.append("<hr size=\"1\" noshade>");
-    sbuf.append(Layout.LINE_SEP);
+	 if(shouldWriteHtmlHeaderAndFooter)
+	 {
+		 sbuf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 
Transitional//EN\"");
+		 sbuf.append(" \"http://www.w3.org/TR/html4/loose.dtd\">");
+		 sbuf.append(Layout.LINE_SEP);
+		 sbuf.append("<html>");
+		 sbuf.append(Layout.LINE_SEP);
+		 sbuf.append("<head>");
+		 sbuf.append(Layout.LINE_SEP);
+		 sbuf.append("<title>" + title + "</title>");
+		 sbuf.append(Layout.LINE_SEP);
+		 if(internalCSS) {
+			getInternalCSS(sbuf);
+		 } else {
+			sbuf.append("<LINK REL=StyleSheet 
HREF=\""+url2ExternalCSS+"\" TITLE=\"Basic\">");
+		 }
+		 sbuf.append(Layout.LINE_SEP);
+		 sbuf.append("</head>");
+		 sbuf.append(Layout.LINE_SEP);
+		 sbuf.append("<body>");
+		 sbuf.append(Layout.LINE_SEP);
+
+		 sbuf.append("<hr size=\"1\" noshade>");
+		 sbuf.append(Layout.LINE_SEP);
+	 }
     
      sbuf.append("Log session start time " + new java.util.Date() + "<br>");
      sbuf.append(Layout.LINE_SEP);
@@ -290,9 +304,12 @@
    public String getFooter() {
      StringBuffer sbuf = new StringBuffer();
      sbuf.append("</table>" + Layout.LINE_SEP);
-    sbuf.append("<br>" + Layout.LINE_SEP);
-    sbuf.append("</body></html>");
-    return sbuf.toString();
+	 if(shouldWriteHtmlHeaderAndFooter)
+	 {
+		sbuf.append("<br>" + Layout.LINE_SEP);
+		sbuf.append("</body></html>");
+    }
+	 return sbuf.toString();
    }

    /**


-- 
==========================================
SD

WARNING: Programming may be habit forming.

Re: HTMLLayout.java Patch

Posted by Mark Womack <mw...@apache.org>.
Hi,

Would it be possible for you to submit this patch into Bugzilla? That way we
won't lose track of it. I would imagine that we can include this or
something like it in the 1.3 release.

thanks for the submission!
-Mark

On 10/3/05, SD <lo...@fishh2o.com> wrote:
>
> Patch for HTMLLayout.java to allow the user of the logger to turn the html
> header/footer off if needed.
>
> I'm using log4j to output some html but I'm doing this within an existing
> webpage. Therefore, I don't need/want the html header/footer that the logger
> normally prints out.
>  Added the member var* shouldWriteHtmlHeaderAndFooter* and the appropriate
> * if* statements to make the desired effect. Also added an* assessor* and*setter
> * for* shouldWriteHtmlHeaderAndFooter*.
>
>
> Thanx for the awesome logging lib.
>