diff --git a/build.xml b/build.xml index c132c44..6c370bf 100644 --- a/build.xml +++ b/build.xml @@ -3,7 +3,7 @@ @@ -72,7 +72,7 @@ - + @@ -170,6 +170,9 @@ + diff --git a/src/java/org/apache/commons/logging/impl/Jdk14Logger.java b/src/java/org/apache/commons/logging/impl/Jdk14Logger.java index a96986a..d3c27e7 100644 --- a/src/java/org/apache/commons/logging/impl/Jdk14Logger.java +++ b/src/java/org/apache/commons/logging/impl/Jdk14Logger.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/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/jerenkrantz/tmp/commons/commons-convert/cvs/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 @@ import org.apache.commons.logging.Log; * @author Scott Sanders * @author Berin Loritsch * @author Peter Donald - * @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 final class Jdk14Logger implements Log { // --------------------------------------------------------- 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 final class Jdk14Logger implements Log { */ 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 final class Jdk14Logger implements Log { */ public void error(Object message) { - logger.log(Level.SEVERE, message.toString()); + log(Level.SEVERE, message.toString(), null); } @@ -145,7 +164,7 @@ public final class Jdk14Logger implements Log { */ 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 final class Jdk14Logger implements Log { */ public void fatal(Object message) { - logger.log(Level.SEVERE, message.toString()); + log(Level.SEVERE, message.toString(), null); } @@ -165,7 +184,7 @@ public final class Jdk14Logger implements Log { */ 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 final class Jdk14Logger implements Log { */ public void info(Object message) { - logger.log(Level.INFO, message.toString()); + log(Level.INFO, message.toString(), null); } @@ -195,7 +214,7 @@ public final class Jdk14Logger implements Log { */ 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 final class Jdk14Logger implements Log { */ public void trace(Object message) { - logger.log(Level.FINEST, message.toString()); + log(Level.FINEST, message.toString(), null); } @@ -275,7 +294,7 @@ public final class Jdk14Logger implements Log { */ 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 final class Jdk14Logger implements Log { */ public void warn(Object message) { - logger.log(Level.WARNING, message.toString()); + log(Level.WARNING, message.toString(), null); } @@ -295,7 +314,7 @@ public final class Jdk14Logger implements Log { */ public void warn(Object message, Throwable exception) { - logger.log(Level.WARNING, message.toString(), exception); + log(Level.WARNING, message.toString(), exception); } diff --git a/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java b/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java index f879d4d..8f4c55d 100644 --- a/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java +++ b/src/java/org/apache/commons/logging/impl/Log4JCategoryLog.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/Attic/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/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/Attic/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; /** *

Implementation of {@link Log} that maps directly to a Log4J @@ -75,7 +75,7 @@ import org.apache.commons.logging.Log; * @author Scott Sanders * @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 @@ public final class Log4JCategoryLog implements Log { /** 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 @@ public final class Log4JCategoryLog implements Log { * 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 TRACE priority.