Logback在启动的时候可能会出现Logback本身自带的日志输出

09:31:36,518 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:31:36,518 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:31:36,518 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/D:/WorkSpace/vertx/build/install/vertx-shadow/lib/vertx-1.0-fat.jar!/logback.xml]
09:31:36,536 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@8bd1b6a - URL [jar:file:/D:/WorkSpace/vertx/build/install/vertx-shadow/lib/vertx-1.0-fat.jar!/logback.xml] is not of type file
09:31:36,569 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
09:31:36,574 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:31:36,576 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [Console]
09:31:36,617 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
09:31:36,619 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [File]
09:31:36,625 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@415138788 - Will use gz compression
09:31:36,626 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@415138788 - Will use the pattern logs/%d{yyyy-MM-dd}-%i.log for the active file
09:31:36,628 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@cb5822 - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/%d{yyyy-MM-dd}-%i.log.gz'.
09:31:36,628 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@cb5822 - Roll-over at midnight.
09:31:36,631 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@cb5822 - Setting initial period to Fri Jan 03 16:48:39 CST 2020
09:31:36,631 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@cb5822 - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
09:31:36,631 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@cb5822 - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
09:31:36,636 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[File] - Active log file name: logs/latest.log
09:31:36,636 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[File] - File property is set to [logs/latest.log]
09:31:36,637 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
09:31:36,637 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [Debug]
09:31:36,638 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1268650975 - Will use gz compression
09:31:36,639 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1268650975 - Will use the pattern logs/debug/%d{yyyy-MM-dd}-%i.log for the active file
09:31:36,639 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b98378d - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/debug/%d{yyyy-MM-dd}-%i.log.gz'.
09:31:36,639 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b98378d - Roll-over at midnight.
09:31:36,640 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b98378d - Setting initial period to Fri Jan 03 16:48:43 CST 2020
09:31:36,640 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b98378d - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
09:31:36,640 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@2b98378d - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
09:31:36,642 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[Debug] - Active log file name: logs/debug/debug.log
09:31:36,642 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[Debug] - File property is set to [logs/debug/debug.log]
09:31:36,643 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ALL
09:31:36,643 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to ALL
09:31:36,643 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [Console] to Logger[ROOT]
09:31:36,643 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [File] to Logger[ROOT]
09:31:36,643 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [Debug] to Logger[ROOT]
09:31:36,643 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:31:36,644 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@475530b9 - Registering current configuration as safe fallback point

根据logback启动日志不能关闭

是由于配置文件logback.xml的格式不正确,需要按照WARN中的操作解决后即可关闭输出

以下是我自用的配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <property name="LOG_DIR" value="logs"/>
    <property name="pattern" value="[%d{HH:mm:ss.SSS}/%level][%thread] %msg%n"/>

    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>TRACE</level>
            <onMatch>DENY</onMatch>
        </filter>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>DENY</onMatch>
        </filter>
    </appender>

    <appender name="File" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_DIR}/latest.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <maxHistory>20</maxHistory>
            <fileNamePattern>${LOG_DIR}/%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
            <maxFileSize>1GB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>TRACE</level>
            <onMatch>DENY</onMatch>
        </filter>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>DENY</onMatch>
        </filter>
    </appender>

    <appender name="Debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_DIR}/debug/debug.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/debug/%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
            <maxHistory>20</maxHistory>
            <maxFileSize>1GB</maxFileSize>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{yyyy-MM-dd:HH:mm:ss.SSS}/%-5level] [%-25thread] [%-25c{0}] %msg%n</pattern>
        </encoder>
    </appender>

    <root level="all">
        <level value="all"/>
        <appender-ref ref="Console"/>
        <appender-ref ref="File"/>
        <appender-ref ref="Debug"/>
    </root>

</configuration>

标签: Logback