[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-cvs
Subject:    cvs commit: jakarta-log4j/src/java/org/apache/log4j/spi LoggingEvent.java
From:       ceki () apache ! org
Date:       2001-08-13 10:22:11
[Download RAW message or body]

ceki        01/08/13 03:22:11

  Modified:    src/java/org/apache/log4j FileAppender.java MDC.java
               src/java/org/apache/log4j/helpers Makefile
                        ThreadLocalMap.java
               src/java/org/apache/log4j/spi LoggingEvent.java
  Removed:     src/java/org/apache/log4j/helpers ITLContext.java
  Log:
  Introducing BufferedIO in FileAppender.
  
  Clean up of MDC.
  
  Revision  Changes    Path
  1.26      +14 -3     jakarta-log4j/src/java/org/apache/log4j/FileAppender.java
  
  Index: FileAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/FileAppender.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- FileAppender.java	2001/08/09 20:16:31	1.25
  +++ FileAppender.java	2001/08/13 10:22:10	1.26
  @@ -11,6 +11,7 @@
   import java.io.Writer;
   import java.io.FileWriter;
   import java.io.OutputStream;
  +import java.io.BufferedOutputStream;
   import java.io.OutputStreamWriter;
   
   import org.apache.log4j.spi.ErrorHandler;
  @@ -57,6 +58,11 @@
     protected boolean qwIsOurs = false;
   
     /**
  +     Do we do bufferedIO? */
  +  protected boolean bufferedIO = false;
  +
  +
  +  /**
        The default constructor does not do anything. 
     */
     public
  @@ -236,11 +242,16 @@
           truncate fileName.  */
     public
     synchronized
  -  void setFile(String fileName, boolean append) throws IOException {
  +  void setFile(String fileName, boolean append, boolean bufferedIO) 
  +                                                            throws IOException {
       LogLog.debug("setFile called: "+fileName+", "+append);
   
  -    reset();
  -    this.setQWForFiles(new FileWriter(fileName, append));
  +    reset();    
  +    Writer fw = new FileWriter(fileName, append);
  +    if(bufferedIO) {
  +      fw = new BufferedOutputStream(fw);
  +    }
  +    this.setQWForFiles(fw);
       //this.tp = new TracerPrintWriter(qw);
       this.fileName = fileName;
       this.fileAppend = append;
  
  
  
  1.8       +66 -15    jakarta-log4j/src/java/org/apache/log4j/MDC.java
  
  Index: MDC.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/MDC.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MDC.java	2001/08/07 22:23:58	1.7
  +++ MDC.java	2001/08/13 10:22:10	1.8
  @@ -9,34 +9,46 @@
   package org.apache.log4j;
   
   import java.util.Hashtable;
  -//import org.apache.log4j.helpers.ThreadLocalMap;
  -import org.apache.log4j.helpers.ITLContext;
  +import org.apache.log4j.helpers.Loader;
  +import org.apache.log4j.helpers.ThreadLocalMap;
   
   /**
      The MDC class supercedes the {@link NDC} class. It provides
      <em>mapped diagnostic contexts</em>. A <em>Mapped Diagnostic
  -   Context</em>, or MDC in short, is an instrument to distinguish
  +   Context</em>, or MDC in short, is an instrument for distinguishing
      interleaved log output from different sources. Log output is
      typically interleaved when a server handles multiple clients
      near-simultaneously.
   
      <p><b><em>The MDC is managed on a per thread basis</em></b>. A
      child thread automatically inherits a <em>copy</em> of the mapped
  -   diagnostic context of its parent which is managed independently of
  -   the parent's context.
  -
  -   
  -
  -   <p>The MDC class requires JDK 1.2. It will not work under JDK 1.1.
  -
  +   diagnostic context of its parent.
  +  
  +   <p>The MDC class requires JDK 1.2 or above. Under JDK 1.1 the MDC
  +   will always return empty values but others will not harm your
  +   application.
      
      @since 1.2
   
      @author Ceki G&uuml;lc&uuml; */
   public class MDC {
     
  -  final static ITLContext context = new ITLContext();
  +  final static MDC mdc = new MDC();
     
  +  static final int HT_SIZE = 7;
  +
  +  boolean java1;
  +  
  +  Object tlm;
  +  
  +  private
  +  MDC() {
  +    java1 = Loader.isJava1();
  +    if(!java1) {
  +      tlm = new ThreadLocalMap();
  +    }
  +  }
  +
     /**
        Put a context value (the <code>o</code> parameter) as identified
        with the <code>key</code> parameter into the current thread's
  @@ -49,7 +61,7 @@
     static
     public
     void put(String key, Object o) {
  -    context.put(key, o);
  +    mdc.put0(key, o);
     }
     
     /**
  @@ -60,14 +72,53 @@
     static 
     public
     Object get(String key) {
  -    return context.get(key);
  +    return mdc.get0(key);
     }
   
  +  /**
  +     Get the current thread's MDC as a hashtable.
  +   */
     public
     static
     Hashtable getContext() {
  -    //return (Hashtable) context.get();
  -    return null;
  +    return mdc.getContext0();
     }
   
  +
  +  private
  +  void put0(String key, Object o) {
  +    if(java1) {
  +      return;
  +    } else {
  +      Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
  +      if(ht == null) {
  +	ht = new Hashtable(HT_SIZE);
  +	((ThreadLocalMap)tlm).set(ht);
  +      }    
  +      ht.put(key, o);
  +    }
  +  }
  +  
  +  private
  +  Object get0(String key) {
  +    if(java1) {
  +      return null;
  +    } else {       
  +      Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
  +      if(ht != null) {
  +	return ht.get(key);
  +      } else {
  +	return null;
  +      }
  +    }
  +  }
  +
  +  private
  +  Hashtable getContext0() {
  +     if(java1) {
  +      return null;
  +    } else {       
  +      return (Hashtable) ((ThreadLocalMap)tlm).get();
  +    }
  +  }
   }
  
  
  
  1.12      +0 -1      jakarta-log4j/src/java/org/apache/log4j/helpers/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/Makefile,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Makefile	2001/08/07 22:23:58	1.11
  +++ Makefile	2001/08/13 10:22:10	1.12
  @@ -21,7 +21,6 @@
   	FileWatchdog.java\
   	Loader.java\
           ThreadLocalMap.java\
  -        ITLContext.java\
   
   SUBDIRS := 
   
  
  
  
  1.3       +14 -0     jakarta-log4j/src/java/org/apache/log4j/helpers/ThreadLocalMap.java
  
  Index: ThreadLocalMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/ThreadLocalMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ThreadLocalMap.java	2001/08/07 22:23:58	1.2
  +++ ThreadLocalMap.java	2001/08/13 10:22:10	1.3
  @@ -1,9 +1,23 @@
  +/*
  + * Copyright (C) The Apache Software Foundation. All rights reserved.
  + *
  + * This software is published under the terms of the Apache Software License
  + * version 1.1, a copy of which has been included  with this distribution in
  + * the LICENSE.txt file.
  + */
   
   package org.apache.log4j.helpers;
   
   import java.util.Hashtable;
   
  +/**
  +   <code>ThreadLocalMap</code> extends {@link InheritableThreadLocal}
  +   to bequeath a copy of the hashtable of the MDC of the parent
  +   thread.
   
  +   @author Ceki G&uuml;lc&uuml;
  +   @since 1.2
  +*/
   final public class ThreadLocalMap extends InheritableThreadLocal {
   
     public
  
  
  
  1.17      +25 -3     jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
  
  Index: LoggingEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- LoggingEvent.java	2001/08/07 22:23:59	1.16
  +++ LoggingEvent.java	2001/08/13 10:22:10	1.17
  @@ -10,6 +10,7 @@
   import org.apache.log4j.Category;
   import org.apache.log4j.Priority;
   import org.apache.log4j.NDC;
  +import org.apache.log4j.MDC;
   
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.helpers.Loader;
  @@ -63,7 +64,7 @@
     private String ndc;
   
     /** The mapped diagnostic context (MDC) of logging event. */
  -  private Hashtable mdc;
  +  private Hashtable mdcCopy;
   
   
     /** Have we tried to do an NDC lookup? If we did, there is no need
  @@ -175,8 +176,29 @@
       return ndc; 
     }
   
  -  //public
  -  //Hashtable getMDC(String key) {
  +  public
  +  Object getMDC(String key) {
  +    Object r;
  +    
  +    if(mdcCopy != null) {
  +      r = mdcCopy.get(key);
  +      if(r != null) {
  +	return r;
  +      }
  +    } 
  +    return MDC.get(key);
  +  }
  +
  +  protected
  +  void getMDCCopy() {
  +    if(mdcLookupRequired) {
  +      ndcLookupRequired = false;
  +      mdcCopy = MDC.getContext();
  +    }
  +  }
  +
  +  
  +
     //  if(mdcLookupRequired) {
     //	mdcLookupRequired = false;
     //	mdc = MDC.getContext();
  
  
  

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic