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 ce...@apache.org on 2004/05/10 21:11:51 UTC

cvs commit: logging-log4j/src/java/org/apache/log4j/db DBHelper.java

ceki        2004/05/10 12:11:51

  Modified:    src/java/org/apache/log4j MDC.java
               src/java/org/apache/log4j/spi LocationInfo.java
                        LoggingEvent.java
               src/java/org/apache/log4j/db DBHelper.java
  Log:
  - Minor cleaning up of LoggingEvent, small fixes
  - Added MDC.pur(String, Object) method for backward compatibility
  
  Revision  Changes    Path
  1.18      +12 -0     logging-log4j/src/java/org/apache/log4j/MDC.java
  
  Index: MDC.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/MDC.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- MDC.java	9 May 2004 18:37:56 -0000	1.17
  +++ MDC.java	10 May 2004 19:11:50 -0000	1.18
  @@ -68,6 +68,18 @@
     }
   
     /**
  +   * Please use the {@link #put(String key, String val)} form instead. The 'val'
  +   * parameter needs to be a string.
  +   * 
  +   * @param key the key for the contextual information
  +   * @param val is transformed into a string before being placed in the MDC
  +   * @deprecated please use the {@link #put(String key, String val)} form.
  +   */
  +  public static void put(String key, Object val) {
  +    put(key, val.toString());
  +  }
  +  
  +  /**
      * Get the context identified by the <code>key</code> parameter.
      *
      *  <p>This method has no side effects.
  
  
  
  1.19      +7 -0      logging-log4j/src/java/org/apache/log4j/spi/LocationInfo.java
  
  Index: LocationInfo.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LocationInfo.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- LocationInfo.java	27 Feb 2004 16:47:34 -0000	1.18
  +++ LocationInfo.java	10 May 2004 19:11:50 -0000	1.19
  @@ -41,6 +41,13 @@
     public static final String NA = "?";
     static final long serialVersionUID = -1325822038990805636L;
   
  +  /**
  +   * NA_LOCATION_INFO is used in conjunction with deserialized LoggingEvents 
  +   * without real location info available.
  +   * @since 1.3
  +   */
  +  public static LocationInfo NA_LOCATION_INFO = new LocationInfo(NA, NA, NA, NA);
  +  
     // Check if we are running in IBM's visual age.
     static boolean inVisualAge = false;
   
  
  
  
  1.56      +32 -27    logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
  
  Index: LoggingEvent.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- LoggingEvent.java	10 May 2004 09:30:16 -0000	1.55
  +++ LoggingEvent.java	10 May 2004 19:11:50 -0000	1.56
  @@ -47,8 +47,6 @@
    *
    * @author Ceki G&uuml;lc&uuml;
    * @author James P. Cakalic
  - *
  - * @since 0.8.2
    */
   public class LoggingEvent
          implements java.io.Serializable {
  @@ -334,25 +332,24 @@
      * information is cached for future use.
      */
     public LocationInfo getLocationInformation() {
  -    if (locationInfo == null) {
  +    if (locationInfo == null && fqnOfLoggerClass != null) {
         locationInfo = new LocationInfo(new Throwable(), fqnOfLoggerClass);
       }
  -
       return locationInfo;
     }
   
  +
     /**
  -   * Set the location information for this logging event. 
  +   * Set the location information for this logging event.
      * @since 1.3
      */
     public void setLocationInformation(LocationInfo li) {
       if (locationInfo != null) {
  -        throw new IllegalStateException("LocationInformation has been already set.");
  +      throw new IllegalStateException("LocationInformation has been already set.");
       }
       locationInfo = li;
     }
  -    
  -  
  +
   
     /**
      * Return the level of this event.
  @@ -491,8 +488,9 @@
       return ndc;
     }
   
  +
     /**
  -   * This method sets the NDC string for this event. 
  +   * This method sets the NDC string for this event.
      * @throws IllegalStateException if ndc had been already set.
      * @since 1.3
      */
  @@ -504,6 +502,7 @@
       ndc = ndcString;
     }
   
  +
     /**
      * Returns the the context corresponding to the <code>key</code> parameter.
      * If there is a local MDC copy, possibly because we are in a logging
  @@ -577,21 +576,22 @@
   
     /**
      * This method creates a new properties map containing a copy of MDC context
  -   * and a copy if the properites in LoggerRepository containing the logger for
  -   * this event.
  -   * @sicne 1.3
  +   * and a copy of the properites in LoggerRepository generating this event.
  +   *
  +   * @since 1.3
      */
  -  public void createProperties() {
  -    if (properties == null) {
  -      properties = new TreeMap();
  -      Map mdcMap = MDC.getContext();
  -      if(mdcMap != null) {
  -        properties.putAll(mdcMap);
  -      }
  -      if (logger != null) {
  -        properties.putAll(logger.getLoggerRepository().getProperties());
  -      }
  +  public Map createProperties() {
  +    Map map = new TreeMap();
  +    Map mdcMap = MDC.getContext();
  +
  +    if (mdcMap != null) {
  +      map.putAll(mdcMap);
  +    }
  +
  +    if (logger != null) {
  +      map.putAll(logger.getLoggerRepository().getProperties());
       }
  +    return map;
     }
   
   
  @@ -616,6 +616,7 @@
   
       // if the key was not found in this even't properties, try the MDC
       value = MDC.get(key);
  +
       if (value != null) {
         return value;
       }
  @@ -631,7 +632,8 @@
   
     /**
      * Returns the set of of the key values in the properties
  -   * for the event or Collections.EMPTY_SET if properties do not exist.
  +   * for the event.
  +   *
      * The returned set is unmodifiable by the caller.
      *
      * @return Set an unmodifiable set of the property keys.
  @@ -639,7 +641,7 @@
      */
     public Set getPropertyKeySet() {
       if (properties == null) {
  -      createProperties();
  +      properties = createProperties();
       }
       return Collections.unmodifiableSet(properties.keySet());
     }
  @@ -764,6 +766,7 @@
       }
     }
   
  +
     /**
      * Set this event's throwable information.
      * @since 1.3
  @@ -776,6 +779,7 @@
       }
     }
   
  +
     private void readLevel(ObjectInputStream ois)
            throws java.io.IOException, ClassNotFoundException {
       int p = ois.readInt();
  @@ -816,9 +820,9 @@
       ois.defaultReadObject();
       readLevel(ois);
   
  -    // Make sure that no location info is available to Layouts
  +    // Make sure that location info instance is set.
       if (locationInfo == null) {
  -      locationInfo = new LocationInfo(null, null);
  +      locationInfo = LocationInfo.NA_LOCATION_INFO;
       }
     }
   
  @@ -846,7 +850,8 @@
      */
     public void setProperty(String key, String value) {
       if (properties == null) {
  -      properties = new Hashtable(5);    // create a small hashtable
  +      // create a copy of MDC and repository properties  
  +      properties = createProperties();  
       }
   
       if (value != null) {
  
  
  
  1.2       +2 -2      logging-log4j/src/java/org/apache/log4j/db/DBHelper.java
  
  Index: DBHelper.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DBHelper.java	10 May 2004 17:26:58 -0000	1.1
  +++ DBHelper.java	10 May 2004 19:11:51 -0000	1.2
  @@ -16,8 +16,8 @@
    */
   public class DBHelper {
     
  -  static short PROPERTIES_EXIST = 0x01;
  -  static short EXCEPTION_EXISTS = 0x02;
  +  public static short PROPERTIES_EXIST = 0x01;
  +  public static short EXCEPTION_EXISTS = 0x02;
     
     static short computeReferenceMask(LoggingEvent event) {
       short mask = 0;
  
  
  

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