base.xml
<?xml version="1.0" encoding="UTF-8"?>
<included>
<property name="log_pattern_default" value="%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n%ex"/>
<property name="log_file_default" value="log/service.log"/>
<property name="log_file_pattern_default" value="log/service.%d{yyyy-MM-dd}.%i.log"/>
<property name="log_file_max_history_default" value="10"/>
<property name="log_file_max_size_default" value="100MB"/>
<property name="log_file_max_total_size_default" value="10GB"/>
<appender name="file_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log_file:-${log_file_default}}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log_file_pattern:-${log_file_pattern_default}}</fileNamePattern>
<maxFileSize>${log_file_max_size:-${log_file_max_size_default}}</maxFileSize>
<maxHistory>${log_file_max_history:-${log_file_max_history_default}}</maxHistory>
<totalSizeCap>${log_file_max_total_size:-${log_file_max_total_size_default}}</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${log_pattern:-${log_pattern_default}}</pattern>
</encoder>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log_pattern:-${log_pattern_default}}</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="stdout"/>
<appender-ref ref="file_out"/>
</root>
</included>
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log_file" value="log/service.log"/>
<property name="log_file_pattern" value="log/service.%d{yyyy-MM-dd}.%i.log"/>
<include resource="top/xinzhang0618/gaohuo/logger/base.xml"/>
<springProfile name="dev,test">
<logger name="top.xinzhang0618.gaohuo" level="debug" additivity="false">
<appender-ref ref="file_out"/>
<appender-ref ref="stdout"/>
</logger>
</springProfile>
<springProfile name="prod">
<logger name="top.xinzhang0618.gaohuo" level="info" additivity="false">
<appender-ref ref="file_out"/>
</logger>
</springProfile>
</configuration>
application.yml
logging:
config: classpath:config/logback-spring.xml