0%

logback关闭启动时自身调试信息打印

问题描述

使用logback打印日志,启动服务时logback会打印一些自身的调试信息如下,会打印它检查了哪些配置、看见了哪些配置:

18:00:22,729 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
18:00:22,729 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
18:00:22,729 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/D:/DeriGateway/DBCompare/target/classes/logback.xml]
18:00:22,770 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
18:00:22,775 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using current interpretation time, i.e. now, as time reference.
18:00:22,788 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="DATETIME" and value="2020-04-01 18:00:22" to the LOCAL scope
18:00:22,788 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
18:00:22,793 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
18:00:22,796 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
18:00:22,813 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
18:00:22,816 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILEOUT]
18:00:22,817 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
18:00:22,828 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@984849465 - No compression will be used
18:00:22,829 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@984849465 - Will use the pattern ./logs//log.%d.%i.log for the active file
18:00:22,830 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2eee9593 - The date pattern is 'yyyy-MM-dd' from file name pattern './logs//log.%d.%i.log'.
18:00:22,830 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2eee9593 - Roll-over at midnight.
18:00:22,832 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2eee9593 - Setting initial period to Wed Apr 01 18:00:22 CST 2020
18:00:22,833 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2eee9593 - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
18:00:22,833 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2eee9593 - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
18:00:22,834 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILEOUT] - Active log file name: ./logs//log.2020-04-01.0.log
18:00:22,834 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILEOUT] - File property is set to [null]
18:00:22,835 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
18:00:22,835 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
18:00:22,835 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILEOUT] to Logger[ROOT]
18:00:22,835 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
18:00:22,836 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@7907ec20 - Registering current configuration as safe fallback point

关闭logback自身调试信息打印

只需增加一行以下配置即可。将状态信息监听器设置为无操作监听器。

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

完整logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
    <property name="ROOT" value="./logs/" />
    <property name="FILESIZE" value="100MB" />
    <property name="MAXHISTORY" value="30" />
    <timestamp key="DATETIME" datePattern="yyyy-MM-dd HH:mm:ss" />
    <!-- 控制台打印 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>
        </encoder>
    </appender>
    <!-- 输入到文件,按日期和文件大小 -->
    <appender name="FILEOUT" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${ROOT}/log.%d.%i.log</fileNamePattern>
            <maxHistory>${MAXHISTORY}</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${FILESIZE}</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>
    <!-- Logger 根目录 -->
    <root level="INFO">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILEOUT" />
    </root>
</configuration>