8月1号 springboot 日志配置
一、springboot 日志配置
application.yml 指定日志文件的位置
logging:
config: classpath:logback-spring.xml
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="60 seconds" debug="false"> <property name="log.lever" value="info" /> <property name="log.maxHistory" value="365" /> <property name="log.filePath" value="/home/appuser/logs/datacollection"></property> <property name="log.pattern" value="%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) |-%-5level [%thread] %c [%L] -| %msg%n" /> <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>${log.pattern}</pattern> </encoder> </appender> <!-- INFO --> <appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 文件路径 --> <file>${log.filePath}/info.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 文件名称 --> <fileNamePattern>${log.filePath}/info/info.%d{yyyy-MM-dd}.log.gz </fileNamePattern> <!-- 文件最大保存历史数量 --> <MaxHistory>${log.maxHistory}</MaxHistory> </rollingPolicy> <encoder> <pattern>${log.pattern}</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- ERROR --> <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 文件路径 --> <file>${log.filePath}/error.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 文件名称 --> <fileNamePattern>${log.filePath}/error/error.%d{yyyy-MM-dd}.log.gz </fileNamePattern> <!-- 文件最大保存历史数量 --> <MaxHistory>${log.maxHistory}</MaxHistory> </rollingPolicy> <encoder> <pattern>${log.pattern}</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <logger name="io" level="${log.lever}"> <appender-ref ref="infoAppender" /> <appender-ref ref="errorAppender" /> </logger> <root level="info"> <appender-ref ref="infoAppender" /> <appender-ref ref="consoleAppender" /> </root> </configuration>