You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2004/05/29 12:43:36 UTC

cvs commit: jakarta-commons/logging/src/test/org/apache/commons/logging/simple CustomConfigTestCase.java DecoratedSimpleLog.java DefaultConfigTestCase.java

rdonkin     2004/05/29 03:43:35

  Modified:    logging/src/java/org/apache/commons/logging/impl
                        SimpleLog.java
               logging/src/test/org/apache/commons/logging/simple
                        CustomConfigTestCase.java DecoratedSimpleLog.java
                        DefaultConfigTestCase.java
  Log:
  Enhanced simple log so that the date and time can be set. Bugzilla issue #27528. Contributed by Dennis Lundberg.
  
  Revision  Changes    Path
  1.19      +29 -7     jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java
  
  Index: SimpleLog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SimpleLog.java	1 Mar 2004 02:12:48 -0000	1.18
  +++ SimpleLog.java	29 May 2004 10:43:35 -0000	1.19
  @@ -52,7 +52,13 @@
    *     included in output messages. Defaults to <code>true</code>.</li>
    * <li><code>org.apache.commons.logging.simplelog.showdatetime</code> -
    *     Set to <code>true</code> if you want the current date and time
  - *     to be included in output messages. Default is false.</li>
  + *     to be included in output messages. Default is <code>false</code>.</li>
  + * <li><code>org.apache.commons.logging.simplelog.dateTimeFormat</code> -
  + *     The date and time format to be used in the output messages.
  + *     The pattern describing the date and time format is the same that is
  + *     used in <code>java.text.SimpleDateFormat</code>. If the format is not
  + *     specified or is invalid, the default format is used.
  + *     The default format is <code>yyyy/MM/dd HH:mm:ss:SSS zzz</code>.</li>
    * </ul>
    *
    * <p>In addition to looking for system properties with the names specified
  @@ -78,6 +84,10 @@
       /** Properties loaded from simplelog.properties */
       static protected final Properties simpleLogProps = new Properties();
   
  +    /** The default format to use when formating dates */
  +    static protected final String DEFAULT_DATE_TIME_FORMAT =
  +        "yyyy/MM/dd HH:mm:ss:SSS zzz";
  +
       /** Include the instance name in the log message? */
       static protected boolean showLogName = false;
       /** Include the short name ( last component ) of the logger in the log
  @@ -87,6 +97,8 @@
       static protected boolean showShortName = true;
       /** Include the current time in the log message */
       static protected boolean showDateTime = false;
  +    /** The date and time format to use in the log message */
  +    static protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
       /** Used to format times */
       static protected DateFormat dateFormatter = null;
   
  @@ -154,9 +166,19 @@
           showDateTime = getBooleanProperty( systemPrefix + "showdatetime", showDateTime);
   
           if(showDateTime) {
  -            dateFormatter = new SimpleDateFormat(
  -                getStringProperty(systemPrefix + "dateformat",
  -                                  "yyyy/MM/dd HH:mm:ss:SSS zzz"));
  +            dateTimeFormat = getStringProperty(systemPrefix + "dateTimeFormat",
  +                                               dateTimeFormat);
  +            if (dateTimeFormat == null || "".equals(dateTimeFormat)) {
  +                // if this property has not been set then use the default
  +                dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
  +            }
  +            try {
  +                dateFormatter = new SimpleDateFormat(dateTimeFormat);
  +            } catch(IllegalArgumentException e) {
  +                // If the format pattern is invalid - use the default format
  +                dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
  +                dateFormatter = new SimpleDateFormat(dateTimeFormat);
  +            }
           }
       }
   
  @@ -170,7 +192,7 @@
       /** The short name of this simple log instance */
       private String shortLogName = null;
   
  -    
  +
       // ------------------------------------------------------------ Constructor
   
       /**
  @@ -252,7 +274,7 @@
        * This method assembles the message
        * and then calls <code>write()</code> to cause it to be written.</p>
        *
  -     * @param type One of the LOG_LEVE_XXX constants defining the log level
  +     * @param type One of the LOG_LEVEL_XXX constants defining the log level
        * @param message The message itself (typically a String)
        * @param t The exception whose stack trace should be logged
        */
  
  
  
  1.5       +4 -3      jakarta-commons/logging/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java
  
  Index: CustomConfigTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CustomConfigTestCase.java	28 Feb 2004 21:46:46 -0000	1.4
  +++ CustomConfigTestCase.java	29 May 2004 10:43:35 -0000	1.5
  @@ -17,7 +17,6 @@
   package org.apache.commons.logging.simple;
   
   
  -import java.io.InputStream;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  @@ -29,7 +28,7 @@
   
   
   /**
  - * <p>TestCase for sipmle logging when running with custom configuration
  + * <p>TestCase for simple logging when running with custom configuration
    * properties.</p>
    *
    * @author Craig R. McClanahan
  @@ -164,6 +163,8 @@
           assertEquals(SimpleLog.LOG_LEVEL_DEBUG, ((SimpleLog) log).getLevel());
   
           // Can we validate the extra exposed properties?
  +        assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
  +                     ((DecoratedSimpleLog) log).getDateTimeFormat());
           assertEquals("DecoratedLogger",
                        ((DecoratedSimpleLog) log).getLogName());
           assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
  
  
  
  1.5       +5 -0      jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DecoratedSimpleLog.java
  
  Index: DecoratedSimpleLog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DecoratedSimpleLog.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DecoratedSimpleLog.java	28 Feb 2004 21:46:46 -0000	1.4
  +++ DecoratedSimpleLog.java	29 May 2004 10:43:35 -0000	1.5
  @@ -41,6 +41,11 @@
       // ------------------------------------------------------------- Properties
   
   
  +    public String getDateTimeFormat() {
  +        return (dateTimeFormat);
  +    }
  +
  +
       public String getLogName() {
           return (logName);
       }
  
  
  
  1.5       +3 -1      jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java
  
  Index: DefaultConfigTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultConfigTestCase.java	28 Feb 2004 21:46:46 -0000	1.4
  +++ DefaultConfigTestCase.java	29 May 2004 10:43:35 -0000	1.5
  @@ -178,6 +178,8 @@
           assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
   
           // Can we validate the extra exposed properties?
  +        assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
  +                     ((DecoratedSimpleLog) log).getDateTimeFormat());
           assertEquals("DecoratedLogger",
                        ((DecoratedSimpleLog) log).getLogName());
           assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org