slf4j-simple
maven引入
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
需要打日志的类中添加 logger引用
private Logger logger = LoggerFactory.getLogger(当前类名.class);
public void testLog() {
logger.info("测试log4j");
}
因为SpringBoot默认包含logback,所以打印日志的时候默认会使用它,需要把它屏蔽掉
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
网友评论