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

Wrong classname when using slf4j inside a wrapper and logging via LoggingEventBuilder

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • 2.0.17
    • None
    • None
    • None

    Description

      I am using the kotlin-logging library which is basically a wrapper around slf4j tailored for kotlin. (Original issue kotlin-logging-416).

      When logging using the LoggingEventBuilder and setting the CallerBoundary accordingly it prints the wrong classname.

      package my.pkg;
      
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import org.slf4j.spi.CallerBoundaryAware;
      
      public class Example {
          private static final LoggingWrapper wrapper = new LoggingWrapper();
      
          public static void main(String[] args) {
              wrapper.logWithEvent("hello");
          }
      }
      
      class LoggingWrapper {
          private Logger underlyingLogger = LoggerFactory.getLogger("anything");
      
          public void logWithEvent(String msg) {
              var builder = underlyingLogger.atInfo();
              // setting the caller boundary to LoggingWrapper
              if(builder instanceof CallerBoundaryAware)
                  ((CallerBoundaryAware) builder).setCallerBoundary(LoggingWrapper.class.getName());
              builder.log(msg);
          }
      }
      

      Running the given example I expect the following output:

      Apr. 06, 2024 6:28:12 AM my.pkg.Example main
      INFORMATION: hello

      However following is printed:

      Apr. 06, 2024 6:28:12 AM my.pkg.LoggingWrapper logWithEvent
      INFORMATION: hello

      Checkout the example: example.zip

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            ceki Ceki Gülcü
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: