Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1429

MarkerFactory.getMarkert(..) doubles logger root, creates extra logger context

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical Critical
    • 1.3.0-alpha10
    • 1.3.0-alpha4

    Description

      Calling MarkerFactory.getMarker("any marker") doubles the logger root, and the logger context. If you want to obtain loggers created before the marker using the factory, you will get new instances. 

       

      Here is an example code: 

      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import org.slf4j.Marker;
      import org.slf4j.MarkerFactory;
      
      public class Main {
      
       public static void main(String[] args) {
      
       Logger l1 = LoggerFactory.getLogger(Main.class);
       Logger l2 = LoggerFactory.getLogger(Main.class);
       if(l1==l2) {
         System.out.println("The first two loggers are the same");
       }
      
       Marker newMarker = MarkerFactory.getMarker("NewMarker");
       Logger l3 = LoggerFactory.getLogger(Main.class);
       if(l1==l3) {
         System.out.println("l1==l3");
       } else {
         System.out.println("l1!=l3");
       }
       }
      }

      Here is the output on my machine:

      The first two loggers are the same
      l1!=l3

      The above code proves that you can obtain the same logger from the factory multiple times. However, after you instantiate a marker using the factory, you will get new instances instead of the old ones.

       

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            kovmate Máté Kovács
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: