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 "Rozensky, Ronald S (Ronald)" <ro...@avaya.com> on 2003/11/07 05:21:12 UTC

HTMLLayout enhancement

I'm posting this in the hopes that someone will find this useful and
possibly get checked in.  It was necessary for me to change the some of
the colors of the HTMLLayout class.  Instead of keeping them hard-coded,
I made some of them configurable as in PatternLayout.  Here are the
diffs:
 
55a56,80
>     Background color of the title bar of the table.
>   */
>   private String tableTitleBarColor = "#336699";
> 
>   /**
>     Background color of the row beneath the title bar.
>   */
>   private String tableTitleColor = "#FFFFFF";
> 
>   /**
>     Background of the color of the error displayed.
>   */
>   private String tableErrorContentsColor = "#993300";
> 
>   /**
>     Font color of the error being displayed.
>   */
>   private String tableErrorFontColor = "White";
> 
>   /**
>     Font size of the error being displayed.
>   */
>   private String tableErrorFontSize = "xx-small";
> 
>   /**
112a138,139
>   /**
>   */
113a141,216
>   void setTableTitleColor(String tableTitleColor) {
>     this.tableTitleColor = tableTitleColor;
>   }
> 
>   /**
>   */
>   public
>   String getTableTitleColor() {
>     return tableTitleColor;
>   }
> 
>   /**
>     Set the background color of the error being displayed.
>   */
>   public
>   void setTableErrorContentsColor(String tableErrorContentsColor) {
>     this.tableErrorContentsColor = tableErrorContentsColor;
>   }
> 
>   /**
>     Return the background color of the error being displayed.
>   */
>   public
>   String getTableErrorContentsColor() {
>     return tableErrorContentsColor;
>   }
> 
>   /**
>     Set the color of the font for the error being displayed.
>   */
>   public
>   void setTableErrorFontColor(String tableErrorFontColor) {
>     this.tableErrorFontColor = tableErrorFontColor;
>   }
> 
>   /**
>     Return the color of the font for the error being displayed.
>   */
>   public
>   String getTableErrorFontColor() {
>     return tableErrorFontColor;
>   }
> 
>   /**
>     Set the size of the font for the error being displayed.
>   */
>   public
>   void setTableErrorFontSize(String tableErrorFontSize) {
>     this.tableErrorFontSize = tableErrorFontSize;
>   }
> 
>   /**
>     Return the size of the font for the error being displayed.
>   */
>   public
>   String getTableErrorFontSize() {
>     return tableErrorFontSize;
>   }
> 
>   /**
>     Set the background color of the title bar.
>   */
>   public
>   void setTableTitleBarColor() {
>     this.tableTitleBarColor = tableTitleBarColor;
>   }
> 
>   /**
>     Get the background color of the title bar.
>   */
>   public
>   String getTableTitleBarColor() {
>     return tableTitleBarColor;
>   }
> 
>   public
166c269
<       sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size :
xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">");
---
>       sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : " +
tableErrorFontSize + ";\" colspan=\"6\" title=\"Nested Diagnostic
Context\">");
173c276
<       sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White;
font-size : xx-small;\" colspan=\"6\">");
---
>       sbuf.append("<tr><td bgcolor=\"" + tableErrorContentsColor + "\"
style=\"color:" + tableErrorFontColor + "; font-size : " +
tableErrorFontSize + ";\" colspan=\"6\">");
209c312
<     sbuf.append("th {background: #336699; color: #FFFFFF; text-align:
left;}" + Layout.LINE_SEP);
---
>     sbuf.append("th {background: " + tableTitleBarColor + "; color:
#FFFFFF; text-align: left;}" + Layout.LINE_SEP);
213c316
<     sbuf.append("<body bgcolor=\"#FFFFFF\" topmargin=\"6\"
leftmargin=\"6\">" + Layout.LINE_SEP);
---
>     sbuf.append("<body bgcolor=\"" + tableTitleColor + "\"
topmargin=\"6\" leftmargin=\"6\">" + Layout.LINE_SEP);
 
 
 
Here is a snippet of a working log4j.xml:
 
        <appender name="mail" class="org.apache.log4j.net.SMTPAppender">
                <param name="Threshold" value="ERROR"/>
                <param name="BufferSize" value="1"/>
                <param name="From" value="tomcat@mesgterm"/>
                <param name="SMTPHost" value="mesgterm.dr.avaya.com"/>
                <param name="Subject" value="Tomcat Error
Notification"/>
                <param name="To" value="rozensky@avaya.com"/>
                <layout class="org.apache.log4j.HTMLLayout">
                     <param name="TableTitleColor" value="#336699"/>
                     <param name="TableTitleColor" value="#FFFFFF"/>
                     <param name="TableErrorContentsColor"
value="#FFFFFF"/>
                     <param name="TableErrorFontColor" value="Black"/>
                     <param name="TableErrorFontSize" value="x-small"/>
                </layout>
        </appender>
 
All the above values have default values, so that:
 
<layout class="org.apache.log4j.HTMLLayout"/>
 
will also work.
 
I'd be happy to pass along the source.
 
Ron
 
Ronald Rozensky
Avaya, Inc.
11399 16th Court North
St. Petersburg FL 33716
727-217-1680
rozensky@avaya.com