0

我有如下的 logback 文件,我想为定义的所有其他 appender 禁用 log printinto STDOUTAppender。我的意思是包下的Classess"com.ttech.pnsender"不要将日志写入控制台附加文件

<?xml version="1.0" encoding="UTF-8" ?>
<configuration scanPeriod="10 seconds" debug="false" scan="false">
    <property name="LOG_DIR" value="logs" />
    <appender name="STDOUTAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern>
        </encoder>
    </appender>


    <appender name="SPRING"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/spring/spring.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/spring.log.%d{yyyy-MM-dd-HH}
            </FileNamePattern>

            <MaxHistory>30</MaxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern>
        </encoder>
    </appender>


    <appender name="PUSHY"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/pushy/pushy.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/pushy/pushy.log.%d{yyyy-MM-dd-HH}
            </FileNamePattern>

            <MaxHistory>30</MaxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern>
        </encoder>
    </appender>



    <appender name="errorAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/error/ERROR.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/error/ERROR.log.%d{yyyy-MM-dd-HH}
            </FileNamePattern>

            <MaxHistory>72</MaxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%date %level [%thread] %msg%n</pattern>
        </encoder>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <appender name="AppAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/application/APPLICATION.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/application/APPLICATION.log.%d{yyyy-MM-dd-HH}
            </FileNamePattern>
        </rollingPolicy>

        <encoder>
            <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="TxnAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/txn/TXN.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/txn/TXN.log.%d{yyyy-MM-dd-HH}
            </FileNamePattern>
        </rollingPolicy>

        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>

    <appender name="AlarmAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/alarm/ALARM.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/alarm/ALARM.log.%d{yyyy-MM-dd}
            </FileNamePattern>
        </rollingPolicy>

        <encoder>
            <pattern>%date %level : %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="C3POAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_DIR}/c3po/c3po.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_DIR}/c3po/c3po.log.%d{yyyy-MM-dd}
            </FileNamePattern>

            <MaxHistory>30</MaxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>

    <logger name="org.springframework">
        <level value="INFO" />
        <appender-ref ref="SPRING" />
    </logger>

    <logger name="com.relayrides.pushy">
        <level value="TRACE" />
        <appender-ref ref="PUSHY" />
    </logger>

    <logger name="TxnLogger">
        <level value="INFO" />
        <appender-ref ref="TxnAppender" />
    </logger>

    <logger name="AlarmLogger">
        <level value="INFO" />
        <appender-ref ref="AlarmAppender" />
    </logger>

    <logger name="com.mchange.v2.c3p0">
        <level value="INFO" />
        <appender-ref ref="C3POAppender" />
    </logger>

    <logger name="com.ttech.pnsender" additivity="true" level="DEBUG">
        <appender-ref ref="AppAppender" />
        <appender-ref ref="errorAppender" />
    </logger>

    <root level="WARN">
        <appender-ref ref="STDOUTAppender" />
    </root>
</configuration>
4

0 回答 0