LogBack配置文件
<?xml version="1.0" encoding="UTF-8"?> <!-- 配置文件修改时重新加载,默认true --> <configuration scan="true"> <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> <property name="CATALINA_BASE" value="**/logs"></property> <!-- 控制台输出 --> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder charset="UTF-8"> <!-- 输出日志记录格式 --> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!-- 第一个文件输出,每天产生一个文件 --> <appender name="FILE1" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 输出文件路径+文件名 --> <fileNamePattern>${CATALINA_BASE}/aa.%d{yyyyMMdd}.log</fileNamePattern> <!-- 保存30天的日志 --> <maxHistory>30</maxHistory> </rollingPolicy> <encoder charset="UTF-8"> <!-- 输出日志记录格式 --> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!-- 第二个文件输出,每天产生一个文件 --> <appender name="FILE2" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${CATALINA_BASE}/bb.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${CATALINA_BASE}/bb.%d{yyyyMMdd}.log</fileNamePattern> <maxHistory>30</maxHistory> </rollingPolicy> <encoder charset="UTF-8"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <appender name="CUSTOM" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${CATALINA_BASE}/custom.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${CATALINA_BASE}/custom.%d{yyyy-MM-dd}.log</fileNamePattern> <!-- keep 30 days' worth of history --> <maxHistory>30</maxHistory> </rollingPolicy> <encoder charset="UTF-8"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!-- 设置日志输出级别 --> <root level="ERROR"> <appender-ref ref="CONSOLE" /> </root> <logger name="file1" level="DEBUG"> <appender-ref ref="FILE1" /> </logger> <logger name="file1" level="INFO"> <appender-ref ref="FILE2" /> </logger> <!-- 自定义logger --> <logger name="custom" level="INFO"> <appender-ref ref="CUSTOM" /> </logger> </configuration>