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/11 11:38:23 UTC

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

ceki        2004/05/11 02:38:23

  Modified:    src/java/org/apache/log4j/spi LoggingEvent.java
               .        .cvsignore
               src/java/org/apache/log4j AsyncAppender.java
  Log:
  Fixed a bug in the way LoggingEvent properties were initialized.
  This was caught in one of our test cases.
  
  Revision  Changes    Path
  1.57      +37 -21    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.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- LoggingEvent.java	10 May 2004 19:11:50 -0000	1.56
  +++ LoggingEvent.java	11 May 2004 09:38:22 -0000	1.57
  @@ -575,23 +575,28 @@
   
   
     /**
  -   * This method creates a new properties map containing a copy of MDC context
  -   * and a copy of the properites in LoggerRepository generating this event.
  +   * If the properties field is null, this method creates a new properties map 
  +   * containing a copy of MDC context and a copy of the properites in 
  +   * LoggerRepository generating this event. If properties is non-null,
  +   * this method does nothing.
      *
      * @since 1.3
      */
  -  public Map createProperties() {
  -    Map map = new TreeMap();
  -    Map mdcMap = MDC.getContext();
  +  public void initializeProperties() {
  +    
  +    if(properties == null) {
  +      Map map = new TreeMap();
  +      Map mdcMap = MDC.getContext();
   
  -    if (mdcMap != null) {
  -      map.putAll(mdcMap);
  -    }
  +      if (mdcMap != null) {
  +        map.putAll(mdcMap);
  +      }
   
  -    if (logger != null) {
  -      map.putAll(logger.getLoggerRepository().getProperties());
  +      if (logger != null) {
  +        map.putAll(logger.getLoggerRepository().getProperties());
  +      }
  +      properties = map;
       }
  -    return map;
     }
   
   
  @@ -640,9 +645,7 @@
      * @since 1.3
      */
     public Set getPropertyKeySet() {
  -    if (properties == null) {
  -      properties = createProperties();
  -    }
  +    initializeProperties();
       return Collections.unmodifiableSet(properties.keySet());
     }
   
  @@ -851,7 +854,7 @@
     public void setProperty(String key, String value) {
       if (properties == null) {
         // create a copy of MDC and repository properties  
  -      properties = createProperties();  
  +      initializeProperties();  
       }
   
       if (value != null) {
  @@ -861,10 +864,16 @@
       }
     }
   
  -
  -  private void writeObject(ObjectOutputStream oos)
  -         throws java.io.IOException {
  -    // Aside from returning the current thread name the wgetThreadName
  +  /**
  +   * This method should be called prior to serializing an event. It should also
  +   * be called when using asynchronous logging, before writing the event on 
  +   * a database, or as an XML element. 
  +   * 
  +   *
  +   * @since 1.3
  +   */
  +  public void prepareForSerialization() {
  +      // Aside from returning the current thread name the wgetThreadName
       // method sets the threadName variable.
       this.getThreadName();
   
  @@ -877,11 +886,18 @@
   
       // This call has a side effect of creating a copy of MDC context information
       // as well as a copy the properties for the containing LoggerRepository.
  -    this.createProperties();
  -
  +    if(properties == null) {
  +      initializeProperties();
  +    }
       // This sets the throwable sting representation of the event throwable.
       this.getThrowableStrRep();
  +    
  +  }
   
  +  private void writeObject(ObjectOutputStream oos)
  +         throws java.io.IOException {
  +    
  +    prepareForSerialization();
       oos.defaultWriteObject();
   
       // serialize this event's level
  
  
  
  1.6       +3 -0      logging-log4j/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/logging-log4j/.cvsignore,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- .cvsignore	17 Sep 2003 16:03:02 -0000	1.5
  +++ .cvsignore	11 May 2004 09:38:23 -0000	1.6
  @@ -9,3 +9,6 @@
   IDEAS
   velocity.log.1
   velocity.log
  +log4j-1.3alpha0.jar
  +log4j-chainsaw-1.3alpha0.jar
  +log4j-lf5-1.3alpha0.jar
  
  
  
  1.36      +1 -1      logging-log4j/src/java/org/apache/log4j/AsyncAppender.java
  
  Index: AsyncAppender.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/AsyncAppender.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- AsyncAppender.java	9 May 2004 18:37:56 -0000	1.35
  +++ AsyncAppender.java	11 May 2004 09:38:23 -0000	1.36
  @@ -92,7 +92,7 @@
       event.getThreadName();
   
       // Get a copy of this thread's MDC.
  -    event.createProperties();
  +    event.initializeProperties();
   
       if (locationInfo) {
         event.getLocationInformation();
  
  
  

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