首页 > 代码库 > log

log

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!--按照范围从小到大排序:OFF level > FATAL > ERROR > WARN > INFO > DEBUG > ALL level;范围大的会包含范围小的-->

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoder对日志进行格式化-->
        <encoder>
            <pattern>
                [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>


    <appender name="FILE-INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <!-- File被写入的文件名-->
        <File>${LOG_PATH}/info.log</File>
        <!--<rollingPolicy>:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!--活动文件的大小-->
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!--控制保留的归档文件的最大数量,超出数量就删除旧文件,单位:月-->
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <!-- encoder对日志进行格式化-->
        <encoder>
            <pattern>
                [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${LOG_PATH}/error.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>

        <!-- encoder对日志进行格式化-->
        <encoder>
            <pattern>
                [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <appender name="FILE-DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${LOG_PATH}/debug.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <!-- encoder对日志进行格式化-->
        <encoder>
            <pattern>
                [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>


    <springProfile name="dev">
        <logger name="com.jd" level="INFO">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
        <logger name="org.springframework" level="WARN">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
    </springProfile>

    <springProfile name="local">
        <logger name="com.aa" level="DEBUG">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
            <!--<appender-ref ref="FILE-DEBUG"/>-->
        </logger>
        <logger name="org.springframework" level="DEBUG">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
            <!--<appender-ref ref="FILE-DEBUG"/>-->
        </logger>
    </springProfile>

    <springProfile name="prod">
        <logger name="com.jd" level="INFO">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
        <logger name="org.springframework" level="WARN">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
    </springProfile>

    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>

</configuration>

 

log