logback.xml
logback-spring.xml
---------
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="60 seconds" debug="false"> <property name="LOG_ALL_FILE_NAME_PATTERN" value="logs/app.%d{yyyy-MM-dd}.%i.log"/> <property name="LOG_SELF_FILE_NAME_PATTERN" value="logs/self.%d{yyyy-MM-dd}.%i.log"/> <!-- 日志格式 --> <property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] --- [%8.8t] %logger{32} : %m %ex%n"/> <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] --- [%t] %logger{32} : %m %ex%n"/> <!--输出到控制台--> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>${CONSOLE_LOG_PATTERN}</pattern> </encoder> </appender> <!--输出到文件--> <appender name="fileAll" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_ALL_FILE_NAME_PATTERN}</fileNamePattern> <!-- 日志保留天数 --> <maxHistory>32</maxHistory> <!-- 日志文件上限大小,达到指定大小后删除旧的日志文件 --> <totalSizeCap>1GB</totalSizeCap> <!-- 每个日志文件的最大值 --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>100MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern>${FILE_LOG_PATTERN}</pattern> </encoder> </appender> <appender name="fileSelf" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_SELF_FILE_NAME_PATTERN}</fileNamePattern> <!-- 日志保留天数 --> <maxHistory>32</maxHistory> <!-- 日志文件上限大小,达到指定大小后删除旧的日志文件 --> <totalSizeCap>1GB</totalSizeCap> <!-- 每个日志文件的最大值 --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>100MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern>${FILE_LOG_PATTERN}</pattern> </encoder> </appender> <!-- (多环境配置日志级别)根据不同的环境设置不同的日志输出级别 --> <springProfile name="default,local,dev,test"> <root level="info"> <appender-ref ref="console"/> <appender-ref ref="fileAll"/> </root> <logger name="com.xxx" level="debug"> <appender-ref ref="fileSelf"/> </logger> </springProfile> <springProfile name="product,pre"> <root level="warn"> <appender-ref ref="fileAll"/> </root> <logger name="com.xxx" level="info"> <appender-ref ref="fileSelf"/> </logger> </springProfile> </configuration>
--------- THE END ---------