logback-spring.xml 3.23 KB
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- 日志名称 -->
    <property name="LOG_NAME" value="uap-boot" />
    <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 -->
    <property name="LOG_HOME" value="logs" />

    <!-- springProperty读取springboot配置属性 -->
    <springProperty scope="context" name="build.profile.id" source="spring.profiles.active" />

    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />

    <!-- 日志控制台输出 -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d %-5level [${LOG_NAME}-${build.profile.id}] [%t] [%c:%L] -| %msg%n</pattern>
        </encoder>
    </appender>

    <!-- 日志文件输出 -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/${LOG_NAME}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--日志文件输出的文件名 -->
            <fileNamePattern>${LOG_HOME}/%d{yyyy-MM-dd}/${LOG_NAME}_%i.log.zip</fileNamePattern>
            <!--日志文件保留天数(FileNamePattern中的%d 格式有关,如果yyyy-MM-dd 则是天数) -->
            <maxHistory>10</maxHistory>
            <!--日志文件最大的大小 -->
            <maxFileSize>10MB</maxFileSize>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d %-5level [${LOG_NAME}-${build.profile.id}] [%t] [%c:%L]-| %msg%n</pattern>
        </encoder>
    </appender>

    <!-- 开发环境 -->
    <springProfile name="dev">
        <root level="INFO">
            <appender-ref ref="CONSOLE" />
        </root>

        <logger name="com.diligrp.assistant" level="DEBUG" additivity="false">
            <appender-ref ref="CONSOLE" />
        </logger>

        <logger name="com.alibaba" level="ERROR" additivity="false">
            <appender-ref ref="CONSOLE" />
        </logger>
    </springProfile>

    <!-- 测试环境 -->
    <springProfile name="test">
        <root level="INFO">
            <appender-ref ref="CONSOLE" />
        </root>

        <logger name="com.diligrp.assistant" level="DEBUG">
            <appender-ref ref="FILE" />
        </logger>

        <logger name="com.alibaba" level="ERROR" additivity="false">
            <appender-ref ref="CONSOLE" />
            <appender-ref ref="FILE" />
        </logger>
    </springProfile>

    <!-- 灰度、生产环境 -->
    <springProfile name="pre,prod">
        <root level="INFO">
            <appender-ref ref="CONSOLE" />
        </root>

        <logger name="com.diligrp.assistant" level="DEBUG">
            <appender-ref ref="FILE" />
        </logger>

        <logger name="com.alibaba" level="ERROR" additivity="false">
            <appender-ref ref="CONSOLE" />
            <appender-ref ref="FILE" />
        </logger>

        <!--  单独给子模块指定日志配置时,请注意additivity的使用
        <logger name="com.diligrp.assistant.boss" level="debug" additivity="false">
            <appender-ref ref="CONSOLE" />
            <appender-ref ref="FILE" />
        </logger>
        -->
    </springProfile>
</configuration>