1
0

If we are not going to log the message anyway, do not waste the effort

to create a Throwable and figure out the calling class and method stuff.

PR:  Bugzilla #18184
Submitted by:  Bruno Dumon <bruno at outerthought.org>


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Craig R. McClanahan
2003-03-31 00:27:08 +00:00
parent b3039e1bbf
commit c12099176f

View File

@@ -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.5 2003/03/30 23:42:36 craigmcc Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/Jdk14Logger.java,v 1.6 2003/03/31 00:27:08 craigmcc Exp $
* $Revision: 1.5 $ * $Revision: 1.6 $
* $Date: 2003/03/30 23:42:36 $ * $Date: 2003/03/31 00:27:08 $
* *
* ==================================================================== * ====================================================================
* *
@@ -77,7 +77,7 @@ import org.apache.commons.logging.Log;
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a> * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a> * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @version $Revision: 1.5 $ $Date: 2003/03/30 23:42:36 $ * @version $Revision: 1.6 $ $Date: 2003/03/31 00:27:08 $
*/ */
public final class Jdk14Logger implements Log { public final class Jdk14Logger implements Log {
@@ -110,22 +110,23 @@ public final class Jdk14Logger implements Log {
// --------------------------------------------------------- Public Methods // --------------------------------------------------------- Public Methods
private void log( Level level, String msg, Throwable ex ) { private void log( Level level, String msg, Throwable ex ) {
// Hack (?) to get the stack trace. if (logger.isLoggable(level)) {
Throwable dummyException=new Throwable(); // Hack (?) to get the stack trace.
StackTraceElement locations[]=dummyException.getStackTrace(); Throwable dummyException=new Throwable();
// Caller will be the third element StackTraceElement locations[]=dummyException.getStackTrace();
String cname="unknown"; // Caller will be the third element
String method="unknown"; String cname="unknown";
if( locations!=null && locations.length >2 ) { String method="unknown";
StackTraceElement caller=locations[2]; if( locations!=null && locations.length >2 ) {
cname=caller.getClassName(); StackTraceElement caller=locations[2];
method=caller.getMethodName(); cname=caller.getClassName();
} method=caller.getMethodName();
}
if( ex==null ) { if( ex==null ) {
logger.logp( level, cname, method, msg ); logger.logp( level, cname, method, msg );
} else { } else {
logger.logp( level, cname, method, msg, ex ); logger.logp( level, cname, method, msg, ex );
}
} }
} }