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>

文章作者: wuzhiyong
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 wuzhiyong !
评论
 上一篇
maven打包插件指定main函数及依赖包 maven打包插件指定main函数及依赖包
问题描述Maven打包jar用的默认插件是maven-jar-plugin,默认Maven生成的JAR包只包含了编译生成的.class文件和项目资源文件。有两个问题: 运行时提示没有主清单属性; 依赖的jar包也没有打包进去. 解决办法
2020-04-02
下一篇 
springboot利用系统变量和配置文件实现灵活配置 springboot利用系统变量和配置文件实现灵活配置
静态方式直接在bootstrap.yml或者application.yml中写死; spring: #mysql数据配置 datasource: driver-class-name: com.mysql.jdbc.Drive
2020-03-31
  目录