Slf4j Log Selection Policy

  mongodb, question

I configured slf4j and morphia in the project.

<dependency>
 <groupId>org.mongodb.morphia</groupId>
 <artifactId>morphia</artifactId>
 <version>1.3.1</version>
 </dependency>
 <!  -- slf4j dependency->
 <dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-simple</artifactId>
 <version>1.7.5</version>
 </dependency>

The log configuration is as follows

private static Logger logger = LoggerFactory.getLogger(MongodbTest.class);
 /**
 * List all database names
 */
 @Test
 public void testSlf4j(){
 logger.debug("lalalala");
 logger.warn("lalala");
 logger.info("lalala");
 }

The following is the output information

April 23, 2018 3:59:18 p.m. org.mongodb.morphia.logging.morphialoggerfactory chooseloggerfactory
 Information: loggerimplfactoryset to org.mongodb.morphia.logging.jdk.jdkloggerfactory
 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [springconfig.xml]
 [main]   INFO org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@9597028: startup date [Mon Apr 23 15:59:19 CST 2018];  root of context hierarchy
 [main] WARN shenzhen.MongodbTest - lalala
 [main] INFO shenzhen.MongodbTest - lalala

Why did slf4j choose morphia’s log instead of slf4j’s simple log

If you want to use slf4j’s log module and introduce org.mongodb.morphia, you should exclude its log part.
The reason for this phenomenon is that when log found the implementation class, it first found mongodb’s log implementation class and instantiated it.
Maven configuration reference exclusion:

<exclusions>
 <exclusion>
 <groupId> XXXXXX </groupId>
 <artifactId> XXXXXX </artifactId>
 </exclusion>
 </exclusions>