logback的配置介绍
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!--<statusListener class="ch.qos.logback.core.status.NopStatusListener" />--> <jmxConfigurator/> <!-- ............... --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern> [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread] [%level] [%logger{36}:%line] - %msg%n </pattern> </encoder> </appender> <!-- INFO.....................,....../data/log/service.log --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${log.path:-/data/log}/${app.name:-service}.log</file> <!-- ........................ --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${log.path:-/data/log}/${app.name:-service}-%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>90</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern> [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread] [%level] [%logger{36}:%line] - %msg%n </pattern> </encoder> </appender> <!-- .................. --> <root level="${log.level:-INFO}"> <appender-ref ref="STDOUT"/> <appender-ref ref="FILE"/> </root> </configuration>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final static Logger logger = LoggerFactory.getLogger(Application_Supplier.class);
logger.info("logback 成功了");
logger.error("logback 成功了");
logger.debug("logback 成功了");