Java项目 使用Logback
2021-03-08 02:33
标签:qos sed ogg public out style enc factory set 添加依赖 2.在src/main/resource 目录下 新建logback配置文件 即可 如下 :logback.xml 使用 Java项目 使用Logback 标签:qos sed ogg public out style enc factory set 原文地址:https://www.cnblogs.com/dreamstar99/p/14208042.htmldependency>
groupId>ch.qos.logbackgroupId>
artifactId>logback-classicartifactId>
version>1.2.3version>
scope>testscope>
dependency>
dependency>
groupId>org.slf4jgroupId>
artifactId>slf4j-apiartifactId>
version>1.7.30version>
dependency>
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>infolevel>
filter>
encoder>
pattern>${LOG_PATTERN}pattern>
charset>UTF-8charset>
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.logFileNamePattern>
MaxHistory>30MaxHistory>
MaxFileSize>10MBMaxFileSize>
rollingPolicy>
encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
pattern>${LOG_PATTERN}pattern>
charset>UTF-8charset>
encoder>
appender>
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 ----------------------");
}
}