Thank you all for the discussion.  I am including a new patch to the current version 
that incorporates the suggested changes.
I personally would prefer org.apache.commons.lang.time.FastDateFormat to 
java.text.SimpleDateFormat, but that would require log4j users to be dependent on 
commons-lang.  Either way, I enjoy the flexibility of being able to specify the date 
format dynamically or at initialization time.

I do have a question concerning local.  The constructor for SimpleDateFormat does not 
provide a constructor that will "localize" the pattern, but it does have 
toLocalPattern and applyLocalPattern methods.  Should these be preferred in this 
situation over toPattern and applyPattern.  Any thoughts concerning this?

--- org/apache/log4j/HTMLLayout.java    Thu Feb 20 02:07:38 2003
+++ HTMLLayout.java     Thu Jan 08 09:20:06 2004
@@ -13,6 +13,14 @@
 
 /**
    This layout outputs events in a HTML table.
+   <p>
+   NOTE: If the <code>timeStampFormat</code> property is set to anything
+   other than null, this class is not thread safe.  However, this will only
+   be a problem if <code>HTMLLayout</code> is used by an appender whose
+   <code>doAppend</code> method is not synchronized.  All the
+   standard appenders inherit from <code>AppenderSkeleton</code> and are
+   therfore safe; <code>AppenderSkeleton</code>'s <code>doAppend</code>
+   method is synchronized.
 
    @author Ceki G&uuml;lc&uuml;
  */
@@ -51,6 +59,7 @@
   boolean locationInfo = false;
 
   String title = "Log4J Log Messages";
+  java.text.SimpleDateFormat timeStampFormatter = null;
 
   /**
      The <b>LocationInfo</b> option takes a boolean value. By
@@ -94,6 +103,41 @@
   String getTitle() {
     return title;
   }
+  
+  /**
+    The <b>TimeStampFormat</b> option takes a String value. This option sets the
+    pattern in which the time for an event is formatted.
+    
+    <p>The pattern should conform to the specification used by
+    <code>java.text.SimpleDateFormat</code>
+
+    <p>Defaults to 'null' in which case the time stamp displayed for the event will
+    be the time in milliseconds since the application was started.
+  */
+  public
+  void setTimeStampFormat(String pattern) {
+       
+       if (pattern == null)
+      timeStampFormatter = null;
+    else if (timeStampFormatter == null)
+      timeStampFormatter = new java.text.SimpleDateFormat(pattern);
+    else
+      timeStampFormatter.applyPattern(pattern);
+  }
+
+  /**
+     Returns the current value of the <b>TimeStampFormat</b> option.
+  */
+  public
+  String getTimeStampFormat() {
+       
+    String pattern = null;
+
+    if (timeStampFormatter != null)
+      pattern = timeStampFormatter.toPattern();
+       
+    return pattern;
+  }
 
  /**
      Returns the content type output by this layout, i.e "text/html".
@@ -122,7 +166,18 @@
     sbuf.append(Layout.LINE_SEP + "<tr>" + Layout.LINE_SEP);
 
     sbuf.append("<td>");
-    sbuf.append(event.timeStamp - event.getStartTime());
+    
+    if (timeStampFormatter == null) {
+      sbuf.append(event.timeStamp - event.getStartTime());
+    }
+    else {
+      sbuf.append(
+        timeStampFormatter.format(
+          new java.util.Date(event.timeStamp)
+        )
+      );
+    }
+      
     sbuf.append("</td>" + Layout.LINE_SEP);
 
     sbuf.append("<td title=\"" + event.getThreadName() + " thread\">");
@@ -247,4 +302,4 @@
   boolean ignoresThrowable() {
     return false;
   }
-}
+}
\ No newline at end of file




DISCLAIMER:
**This E-mail and any of its attachments may contain Lincoln National Corporation 
proprietary information, which is privileged, confidential, or subject to copyright 
belonging to the Lincoln National Corporation family of companies. This E-mail is 
intended solely for the use of the individual or entity to which it is addressed. If 
you are not the intended recipient of this E-mail, you are hereby notified that any 
dissemination, distribution, copying, or action taken in relation to the contents of 
and attachments to this E-mail is strictly prohibited and may be unlawful. If you have 
received this E-mail in error, please notify the sender immediately and permanently 
delete the original and any copy of this E-mail and any printout. Thank You.**

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to