标签:qos sed ogg public out style enc factory set
添加依赖
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.30</version> </dependency>
2.在src/main/resource 目录下 新建logback配置文件 即可 如下 :logback.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="10 seconds"> <property name="LOG_HOME" value="./logs" /> <property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n" /> <!--输出到控制台 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>info</level> </filter> <encoder> <pattern>${LOG_PATTERN}</pattern> <charset>UTF-8</charset> </encoder> </appender> <!--输出到文件 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <FileNamePattern>${LOG_HOME}/project-name.%d{yyyy-MM-dd}.%i.log</FileNamePattern> <MaxHistory>30</MaxHistory> <MaxFileSize>10MB</MaxFileSize> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>${LOG_PATTERN}</pattern> <charset>UTF-8</charset> </encoder> </appender> <!-- 设置 log 级别 info --> <root level="info"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>
使用
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Test { private Logger logger = LoggerFactory.getLogger(this.getClass()); public void test() { logger.info("----------------------Start ----------------------"); } }
标签:qos sed ogg public out style enc factory set
原文地址:https://www.cnblogs.com/dreamstar99/p/14208042.html