base.xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <included>
    3. <property name="log_pattern_default" value="%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n%ex"/>
    4. <property name="log_file_default" value="log/service.log"/>
    5. <property name="log_file_pattern_default" value="log/service.%d{yyyy-MM-dd}.%i.log"/>
    6. <property name="log_file_max_history_default" value="10"/>
    7. <property name="log_file_max_size_default" value="100MB"/>
    8. <property name="log_file_max_total_size_default" value="10GB"/>
    9. <appender name="file_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
    10. <file>${log_file:-${log_file_default}}</file>
    11. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
    12. <fileNamePattern>${log_file_pattern:-${log_file_pattern_default}}</fileNamePattern>
    13. <maxFileSize>${log_file_max_size:-${log_file_max_size_default}}</maxFileSize>
    14. <maxHistory>${log_file_max_history:-${log_file_max_history_default}}</maxHistory>
    15. <totalSizeCap>${log_file_max_total_size:-${log_file_max_total_size_default}}</totalSizeCap>
    16. </rollingPolicy>
    17. <encoder>
    18. <pattern>${log_pattern:-${log_pattern_default}}</pattern>
    19. </encoder>
    20. </appender>
    21. <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
    22. <encoder>
    23. <pattern>${log_pattern:-${log_pattern_default}}</pattern>
    24. </encoder>
    25. </appender>
    26. <root level="info">
    27. <appender-ref ref="stdout"/>
    28. <appender-ref ref="file_out"/>
    29. </root>
    30. </included>

    logback-spring.xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <configuration>
    3. <property name="log_file" value="log/service.log"/>
    4. <property name="log_file_pattern" value="log/service.%d{yyyy-MM-dd}.%i.log"/>
    5. <include resource="top/xinzhang0618/gaohuo/logger/base.xml"/>
    6. <springProfile name="dev,test">
    7. <logger name="top.xinzhang0618.gaohuo" level="debug" additivity="false">
    8. <appender-ref ref="file_out"/>
    9. <appender-ref ref="stdout"/>
    10. </logger>
    11. </springProfile>
    12. <springProfile name="prod">
    13. <logger name="top.xinzhang0618.gaohuo" level="info" additivity="false">
    14. <appender-ref ref="file_out"/>
    15. </logger>
    16. </springProfile>
    17. </configuration>

    application.yml

    1. logging:
    2. config: classpath:config/logback-spring.xml