commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging/impl Jdk14Logger.java Log4JCategoryLog.java
Date Mon, 06 May 2002 21:32:38 GMT
costin      02/05/06 14:32:37

  Modified:    logging  build.xml
               logging/src/java/org/apache/commons/logging/impl
                        Jdk14Logger.java Log4JCategoryLog.java
  Log:
  Few small (?) fixes:
  
  - for JDK1.4, include the correct class/method. This uses a hack to
  extract the information from the stack trace - probably slow, but
  it's better to get the correct information.
  
  - for log4j, check if log4j is initialized ( by checking if any appenders
  are present ). Set a default configuration if it is not initialized.
  
  Revision  Changes    Path
  1.14      +5 -2      jakarta-commons/logging/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/build.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- build.xml	20 Feb 2002 23:02:01 -0000	1.13
  +++ build.xml	6 May 2002 21:32:37 -0000	1.14
  @@ -3,7 +3,7 @@
   
   <!--
           "Logging" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.13 2002/02/20 23:02:01 craigmcc Exp $
  +        $Id: build.xml,v 1.14 2002/05/06 21:32:37 costin Exp $
   -->
   
   
  @@ -72,7 +72,7 @@
     <property name="compile.deprecation"     value="false"/>
   
     <!-- Should Java compilations set the 'optimize' compiler option? -->
  -  <property name="compile.optimize"        value="true"/>
  +  <property name="compile.optimize"        value="false"/>
   
     <!-- Construct compile classpath -->
     <path id="compile.classpath">
  @@ -170,6 +170,9 @@
       <copy  todir="${build.home}/classes" filtering="on">
         <fileset dir="${source.home}" excludes="**/*.java"/>
       </copy>
  +    <jar jarfile="${build.home}/commons-${component.name}.jar"
  +         basedir="${build.home}/classes"
  +         manifest="${build.home}/conf/MANIFEST.MF"/>
     </target>
   
   
  
  
  
  1.3       +35 -16    jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Jdk14Logger.java
  
  Index: Jdk14Logger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Jdk14Logger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Jdk14Logger.java	29 Apr 2002 16:48:09 -0000	1.2
  +++ Jdk14Logger.java	6 May 2002 21:32:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Jdk14Logger.java,v
1.2 2002/04/29 16:48:09 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/29 16:48:09 $
  + * $Header: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Jdk14Logger.java,v
1.3 2002/05/06 21:32:37 costin Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/05/06 21:32:37 $
    *
    * ====================================================================
    *
  @@ -77,7 +77,7 @@
    * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
  - * @version $Revision: 1.2 $ $Date: 2002/04/29 16:48:09 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/06 21:32:37 $
    */
   
   public final class Jdk14Logger implements Log {
  @@ -109,13 +109,32 @@
   
       // --------------------------------------------------------- Public Methods
   
  +    private void log( Level level, String msg, Throwable ex ) {
  +        // Hack (?) to get the stack trace.
  +        Throwable dummyException=new Throwable();
  +        StackTraceElement locations[]=dummyException.getStackTrace();
  +        // Caller will be the third element
  +        String cname="unknown";
  +        String method="unknown";
  +        if( locations!=null && locations.length >2 ) {
  +            StackTraceElement caller=locations[2];
  +            cname=caller.getClassName();
  +            method=caller.getMethodName();
  +        }
  +
  +        if( ex==null ) {
  +            logger.logp( level, cname, method, msg );
  +        } else {
  +            logger.logp( level, cname, method, msg, ex );
  +        }
  +    }
   
       /**
        * Log a message with debug log level.
        */
       public void debug(Object message) {
   
  -        logger.log(Level.FINE, message.toString());
  +        log(Level.FINE, message.toString(), null);
   
       }
   
  @@ -125,7 +144,7 @@
        */
       public void debug(Object message, Throwable exception) {
   
  -        logger.log(Level.FINE, message.toString(), exception);
  +        log(Level.FINE, message.toString(), exception);
   
       }
   
  @@ -135,7 +154,7 @@
        */
       public void error(Object message) {
   
  -        logger.log(Level.SEVERE, message.toString());
  +        log(Level.SEVERE, message.toString(), null);
   
       }
   
  @@ -145,7 +164,7 @@
        */
       public void error(Object message, Throwable exception) {
   
  -        logger.log(Level.SEVERE, message.toString(), exception);
  +        log(Level.SEVERE, message.toString(), exception);
   
       }
   
  @@ -155,7 +174,7 @@
        */
       public void fatal(Object message) {
   
  -        logger.log(Level.SEVERE, message.toString());
  +        log(Level.SEVERE, message.toString(), null);
   
       }
   
  @@ -165,7 +184,7 @@
        */
       public void fatal(Object message, Throwable exception) {
   
  -        logger.log(Level.SEVERE, message.toString(), exception);
  +        log(Level.SEVERE, message.toString(), exception);
   
       }
   
  @@ -185,7 +204,7 @@
        */
       public void info(Object message) {
   
  -        logger.log(Level.INFO, message.toString());
  +        log(Level.INFO, message.toString(), null);
   
       }
   
  @@ -195,7 +214,7 @@
        */
       public void info(Object message, Throwable exception) {
   
  -        logger.log(Level.INFO, message.toString(), exception);
  +        log(Level.INFO, message.toString(), exception);
   
       }
   
  @@ -265,7 +284,7 @@
        */
       public void trace(Object message) {
   
  -        logger.log(Level.FINEST, message.toString());
  +        log(Level.FINEST, message.toString(), null);
   
       }
   
  @@ -275,7 +294,7 @@
        */
       public void trace(Object message, Throwable exception) {
   
  -        logger.log(Level.FINEST, message.toString(), exception);
  +        log(Level.FINEST, message.toString(), exception);
   
       }
   
  @@ -285,7 +304,7 @@
        */
       public void warn(Object message) {
   
  -        logger.log(Level.WARNING, message.toString());
  +        log(Level.WARNING, message.toString(), null);
   
       }
   
  @@ -295,7 +314,7 @@
        */
       public void warn(Object message, Throwable exception) {
   
  -        logger.log(Level.WARNING, message.toString(), exception);
  +        log(Level.WARNING, message.toString(), exception);
   
       }
   
  
  
  
  1.4       +27 -7     jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java
  
  Index: Log4JCategoryLog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Log4JCategoryLog.java	7 Mar 2002 22:32:47 -0000	1.3
  +++ Log4JCategoryLog.java	6 May 2002 21:32:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java,v
1.3 2002/03/07 22:32:47 costin Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/03/07 22:32:47 $
  + * $Header: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java,v
1.4 2002/05/06 21:32:37 costin Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/05/06 21:32:37 $
    *
    * ====================================================================
    *
  @@ -62,9 +62,9 @@
   
   package org.apache.commons.logging.impl;
   
  -import org.apache.log4j.Category;
  -import org.apache.log4j.Priority;
  +import org.apache.log4j.*;
   import org.apache.commons.logging.Log;
  +import java.util.Enumeration;
   
   /**
    * <p>Implementation of {@link Log} that maps directly to a Log4J
  @@ -75,7 +75,7 @@
    * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
    * @author Rod Waldhoff
    * @author Robert Burrell Donkin
  - * @version $Id: Log4JCategoryLog.java,v 1.3 2002/03/07 22:32:47 costin Exp $
  + * @version $Id: Log4JCategoryLog.java,v 1.4 2002/05/06 21:32:37 costin Exp $
    */
   public final class Log4JCategoryLog implements Log {
   
  @@ -85,6 +85,8 @@
       /** The fully qualified name of the Log4JCategoryLog class. */
       private static final String FQCN = Log4JCategoryLog.class.getName();
       
  +    private static boolean initialized=false;
  +    private static String LAYOUT="%r [%t] %p %c{2} %x - %m%n";
   
       /** Log to this category */
       private Category category = null;
  @@ -97,18 +99,36 @@
        * Base constructor
        */
       public Log4JCategoryLog(String name) {
  -        category = Category.getInstance(name);
  +        this( Category.getInstance(name));
       }
   
       /** For use with a log4j factory
        */
       public Log4JCategoryLog(Category category ) {
  +        if( ! initialized ) {
  +            initialize();
  +        }
           this.category=category;
       }
   
   
       // ---------------------------------------------------------- Implmentation
   
  +    private void initialize() {
  +        Category root=Category.getRoot();
  +        Enumeration appenders=root.getAllAppenders();
  +        if( appenders==null || ! appenders.hasMoreElements() ) {
  +            // No config, set some defaults ( consistent with
  +            // commons-logging patterns ).
  +            ConsoleAppender app=new ConsoleAppender(new PatternLayout( LAYOUT ),
  +                                                    ConsoleAppender.SYSTEM_ERR );
  +            
  +            root.addAppender( app );
  +            root.setPriority( Priority.INFO );
  +        }
  +        initialized=true;
  +    }
  +    
   
       /**
        * Log a message to the Log4j Category with <code>TRACE</code> priority.
  
  
  

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


Mime
View raw message