commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Bateman (JIRA)" <>
Subject [jira] Updated: (LOGGING-137) LogFactory.getLog()
Date Wed, 11 Aug 2010 02:57:21 GMT


Doug Bateman updated LOGGING-137:


Based on your feedback, here are 3 new versions available for you to choose.

Version 0 is basically what you've seen before.  I fixed a few comments.
Version 1 scans the call stack once, and then stores the indexes as constants.
Version 2 simply asserts it should drop 2 stack frames and avoids much of the scanning.

Good news is reflection stopped being an issue once we replaced the reflection call to Thread.getStackTrace()
with the non-reflection call to Throwable.fillInStackTrace().  This is what makes version
2 possible.

However, I'm not sure how standard Throwable.fillInStackTrace() and Throwable.printStackTrace(err)
are across JVM versions and vendors.  For example, are either "fillInStackTrace() or "printStackTrace()"
included?  Generally no.  But could there be a JVM out there which did?  Was the exact behavior
clearly defined as early as Java 1.1?  Hence I worry about Version 2 making too many assumptions
and prefer version 1.

> LogFactory.getLog()
> -------------------
>                 Key: LOGGING-137
>                 URL:
>             Project: Commons Logging
>          Issue Type: New Feature
>    Affects Versions: 1.1.2
>            Reporter: Doug Bateman
>         Attachments:,,,,
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
> Presently, in Apache Commons, the most common way to get a logger is to do something
> public class MyClass {
>     private static Log log = LogFactory.getLog(MyClass.class);
> }
> Notice how MyClass.class (or alternatively a string name) is passed as a parameter. 
The annoying aspect of this is that sometimes the class name doesn't get updated when doing
copy/paste operations.  A desirable alternative might be:
> public class MyClass {
>     private static Log log = LogFactory.getLog(); //class name inferred from call stack
> }
> With such an approach there are two possible concerns I can foresee:
>     * Call stack inspection isn't terribly fast.  However since Loggers are generally
initialized only once, when the class is first loaded, performance isn't likely to be a major
>     * Commons-logging is Java 1.1 compatible.  Thus care must be taken to ensure compatibility
isn't broken.
>     * Commons-logging doesn't depend on commons-lang, and thus the utilities in commons-lang
cannot be used.
> In Java 1.4, the call stack is easily obtained using Thread.getCallStack().  Prior to
Java 1.4, the only way to obtain the call stack is to inspect the stack trace of an exception.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message