JDK-4899304 : Logger should be able to determine class, metod, line-no. from stack trace.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Future Project
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-07-31
  • Updated: 2005-05-02
  • Resolved: 2005-05-02
Related Reports
Relates :  
Description

Name: rl43681			Date: 07/31/2003


A DESCRIPTION OF THE REQUEST :
java.util.logging.Logger

The Logger class in java.util.logging has several methods where the caller must suply class name and metod.

This is a drawback when doing hevy refactoring. (Ok. the class name can be stated in the caller as this.getClass().getName(), but the method?)

Wouldn't it be possible to extract this information from the stack? (Throwable objects already have StackTraceElement objects). Maybe it could be a feature on the current Thread object to provide this.

Actually this ended upp as two suggestions.
1) Provide getStackTrace() on the Thread class.
2) Let the Logger methods for logging figure out class and method of the caller by using getStackTrace(). Plus addition of line number in log output.

JUSTIFICATION :
Most important is that it would make refactoring much simpler.
Second is that the Log call would be more compact, less error prone and easier to write.


CUSTOMER SUBMITTED WORKAROUND :

Throwable t = new Throwable();
StackTraceElement[] stack = t.getStackTrace();
(Incident Review ID: 193265) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
14-06-2004

EVALUATION This would be useful and is doable but will need to wait for a later release ###@###.### 2003-08-29 ###@###.### 2005-05-02 20:30:42 GMT
29-08-2003