创建项目
编写日志配置
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
[logback-demo] %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5p] %c:%L - %m%n
</pattern>
</encoder>
<!--
ThresholdFilter:满足level以上的日志级别
-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<root>
<!--
定义根日志输出最低日志级别,默认为debug
-->
<level value="info"/>
<appender-ref ref="console"/>
</root>
</configuration>
日志测试类
public class Demo {
public static void main(String[] args) {
//创建日志记录对象
Logger logger = LoggerFactory.getLogger(Demo.class);
logger.trace("This is TRACE message!");
logger.debug("This is DEBGU message!");
logger.info("This is INFO message!");
logger.warn("This is WARN message!");
logger.error("This is ERROR message!");
}
}
查看测试结果