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

Logger.getLogger() enhancement

XMLWordPrintable

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

      It's a very common practice to obtain a logger for each class, like this:

      class Foo {
        static Logger logger = Logger.getLogger(Foo.class.getName());
      }

      In fact in many logging libraries, there's the form of the getLogger method that takes a Class object,
      so that you can write it as:

      class Foo {
        static Logger logger = Logger.getLogger(Foo.class);
      }

      The java.util.logging package should support this.

      We can actually go one step further and allow applications to be written like this:

      class Foo {
        static Logger logger = Logger.getClassLogger();
      }

      This can be implemented as:

          public static Logger getClassLogger() {
              StackTraceElement[] trace = Thread.currentThread().getStackTrace();
              return Logger.getLogger(trace[1].getClassName());
          }

      (In JDK, either this needs to be done in the priviledged block to avoid possible SecurityException)

      In this way, there's less characters to type, and more importantly, this line can be cut&pasted from one class to another.

            Unassigned Unassigned
            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: