Console console display

I have a logback.xml file containing the following:

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <param name="Target" value="System.out"/>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
    <encoder>
        <pattern>%date %-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<appender name="debugfile" class="ch.qos.logback.core.rolling.RollingFileAppender" >
    <file>debugFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>debugFile.%d{yyyy-MM-dd}.log</fileNamePattern>
        <MaxHistory>30</MaxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%date %-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<appender name="infofile" class="ch.qos.logback.core.rolling.RollingFileAppender" >
    <file>infoFile.log</file>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>infoFile_%i.log</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>3</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>1MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%date %-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<appender name="warnfile" class="ch.qos.logback.core.rolling.RollingFileAppender" >
    <file>infoFile.log</file>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>WARN</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>warnFile_%i.log</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>3</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>1MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%date %-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<!-- Setup the Root category -->
<root>
    <appender-ref ref="console"/>
    <appender-ref ref="debugfile"/>
    <appender-ref ref="infofile"/>
<appender-ref ref="warnfile"/>
</root>

      

I want it to only show logs of INFO level or more. So, I added ThresholdFilter and set its level to INFO. This worked for RollingFileAppender (where one includes INFO and more and the other includes DEBUG and more).

It didn't matter as console statements still included DEBUG level statements. Can anyone tell me why?

+3


source to share


1 answer


I can't guarantee this will work, haven't actually tested the setup.
Add an item after yours.

<logger name="ch.qos.logback" level="INFO">
    <appender-ref ref="console" />
</logger>

      



This should change the logging level of only referenced appendices to the desired level.

See the Logback docs for more information on thinking here.

0


source







All Articles