1.导入pomyil
<!--slf4j core 使用slf4j必須添加-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.27</version>
</dependency>
<!-- 2.使用logback实现 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
2.默认使用logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %c [%thread] %-5level %msg%n"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target> <!--日志格式配置-->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${pattern}</pattern>
</encoder>
</appender>
<root level="ALL">
<appender-ref ref="console"/>
</root>
</configuration>
3.使用
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Test {
private final static Logger log = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) {
log.info("ddddd");
}
}
标签:slf4j,Test,Slf4j,static,门面,org,Logger,logback
From: https://www.cnblogs.com/NIAN2011/p/16729419.html