Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4899304

Logger should be able to determine class, metod, line-no. from stack trace.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Future Project
    • Icon: P4 P4
    • None
    • 6
    • core-libs



      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)
      ======================================================================

            Unassigned Unassigned
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: