Máté Kovács created LOGBACK-1429: ------------------------------------ Summary: MarkerFactory.getMarkert(..) doubles logger root, creates extra logger congext Key: LOGBACK-1429 URL: https://jira.qos.ch/browse/LOGBACK-1429 Project: logback Issue Type: Bug Components: logback-classic, logback-core Affects Versions: 1.3.0-alpha4 Environment: uname -a Linux mate-Latitude-5580 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -version openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2, mixed mode) Command line running the code is: /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -javaagent:/home/mate/work/idea-IC-181.5281.24/lib/idea_rt.jar=45441:/home/mate/work/idea-IC-181.5281.24/bin -Dfile.encoding=UTF-8 -classpath /home/mate/work/trials/doubleLoggerRoot/out/production/doubleLoggerRoot:/home/mate/.m2/repository/ch/qos/logback/logback-classic/1.3.0-alpha4/logback-classic-1.3.0-alpha4.jar:/home/mate/.m2/repository/ch/qos/logback/logback-core/1.3.0-alpha4/logback-core-1.3.0-alpha4.jar:/home/mate/.m2/repository/org/slf4j/slf4j-api/1.8.0-beta1/slf4j-api-1.8.0-beta1.jar:/home/mate/.m2/repository/com/sun/mail/javax.mail/1.6.0/javax.mail-1.6.0.jar:/home/mate/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar hu.alerant.Main Reporter: Máté Kovács Assignee: Logback dev list Priority: Critical 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: {code:java} 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"); } } }{code} Here is the output on my machine: {noformat} The first two loggers are the same l1!=l3{noformat} 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. -- This message was sent by Atlassian JIRA (v7.3.1#73012) _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-dev