Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-296

Add default logger method

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • None
    • 1.7.x
    • Core API
    • None
    • Operating System: All
      Platform: All

    Description

      The typical way of adding logging to a class involves a reference to the class itself:
      private static final Logger kLogger = LoggerFactory.getLogger(MyClass.class);

      Not all tooling catches renames and whatnot – I've had several occasions where the old class reference inadvertently came along for the ride and made for misleading logs.

      I started putting this into a little utility class in my projects to prevent this and I think it would be a good addition to LoggerFactory. While the stacktrace calls might not be the cheapest, it's only hit during class initialization.

      public static Logger getDefaultClassLogger()

      { return LoggerFactory.getLogger(Thread.currentThread().getStackTrace()[2].getClassName()); }

      Attachments

        Activity

          People

            slf4j-dev SLF4J developers list
            ggerard@gmail.com ggerard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: