<?xml version="1.0"?>
<configuration>
<property name="log.path" value="./logs"/>
<appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/info.log</file>
<append>true</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss}`%m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/info.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="asyncInfoAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="infoAppender"/>
<queueSize>10000</queueSize>
</appender>
<appender name="accessAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/access.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/access.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="asyncAccessAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="accessAppender"/>
<queueSize>10000</queueSize>
</appender>
<appender name="serverAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/server.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/server.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="asyncServerAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="serverAppender"/>
<queueSize>10000</queueSize>
</appender>
<appender name="tracerAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/tracer.log</file>
<append>true</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/tracer.%d{yyyy-MM-dd_HH}.log</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="access_log" level="info" additivity="false">
<appender-ref ref="asyncAccessAppender"/>
</logger>
<logger name="info" level="info" additivity="false">
<appender-ref ref="asyncInfoAppender"/>
</logger>
<root level="debug">
<appender-ref ref="asyncServerAppender"/>
<appender-ref ref="asyncInfoAppender"/>
<appender-ref ref="stdout"/>
</root>
</configuration>
依赖引入
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
复制即可用 按天生成需把HH去掉 具体可查看官方文档