引入依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
application.properties
logging.config=classpath:logback-zhw.xml
logback-zhw.xml放在resource目录下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志级别 -->
<property name="logLevel" value="INFO"/>
<!-- 日志地址 -->
<property name="logPath" value="./logs_zhw"/>
<!-- 最大保存时间 -->
<property name="maxHistory" value="30"/>
<property name="maxFileSize" value="128MB" />
<!-- 异步缓冲队列的深度,该值会影响性能.默认值为256 -->
<!--<property name="queueSize" value="512"/>-->
<!-- 控制台打印日志的相关配置 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--<level>DEBUG</level>-->
<!--<onMatch>DENY</onMatch>-->
<!--<onMismatch>ACCEPT</onMismatch>-->
<!--</filter>-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-4relative [%thread] %-5level %logger{35} : %msg%n</pattern>
</encoder>
</appender>
<!-- 文件保存日志的相关配置,同步 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--<level>DEBUG</level>-->
<!--<onMatch>DENY</onMatch>-->
<!--<onMismatch>ACCEPT</onMismatch>-->
<!--</filter>-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log</fileNamePattern>
<!--<fileNamePattern>${logPath}/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.%i.log</fileNamePattern>-->
<cleanHistoryOnStart>true</cleanHistoryOnStart>
<maxHistory>${maxHistory}</maxHistory>
<!--<totalSizeCap>8GB</totalSizeCap>-->
<!--<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!--<maxFileSize>${maxFileSize}</maxFileSize>-->
<!--</timeBasedFileNamingAndTriggeringPolicy>-->
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-4relative [%thread] %-5level %logger{35} : %msg%n</pattern>
</layout>
</appender>
<!--<appender name="file_async" class="ch.qos.logback.classic.AsyncAppender">-->
<!--<appender-ref ref="file"/>-->
<!--</appender>-->
<!-- mapper文件路径 -->
<logger name="com.zhw.learning.mapper" level="DEBUG"/>
<root level="${logLevel}">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
</configuration>
backRoads
发布了30 篇原创文章 · 获赞 4 · 访问量 527
私信
关注