【日志】logback scanPeriod is not working 配置不生效解决

logback scanPeriod is not working

logback scanPeriod 配置不生效解决

【日志】logback scanPeriod is not working 配置不生效解决_第1张图片

必须修改 target 内部的才能生效,修改 resources的 logback.xml 不生效。
You must modify the content of target‘s logback.xml instead of that of resources.

Demo
1、logback.xml (6秒扫描一次,待会把 indi 的level改成error看效果)



    
    
        
            %d{yyyy-MM-dd HH:mm:ss} %-5level [%thread%X{sourceThread}]%logger{24} - %msg%n
        
    
    
    
        
    

    

    
        
    

2、Demo.class

package indi.sword.logback.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Demo {
    public static void main(String[] arg) throws Exception{
        Logger logger = LoggerFactory.getLogger(Demo.class);
        while(true) {
            Thread.sleep(1000);
            logger.debug("debug");
            logger.info("info");
            logger.warn("warn");
            logger.error("error");

            logger.error("======");
        }
    }
}

3、效果

2019-03-04 11:10:32 ERROR [main]i.s.logback.demo.Demo - ======
2019-03-04 11:10:33 INFO  [main]i.s.logback.demo.Demo - info
2019-03-04 11:10:33 WARN  [main]i.s.logback.demo.Demo - warn
2019-03-04 11:10:33 ERROR [main]i.s.logback.demo.Demo - error
2019-03-04 11:10:33 ERROR [main]i.s.logback.demo.Demo - ======
2019-03-04 11:10:34 INFO  [main]i.s.logback.demo.Demo - info
2019-03-04 11:10:34 WARN  [main]i.s.logback.demo.Demo - warn
2019-03-04 11:10:34 ERROR [main]i.s.logback.demo.Demo - error
2019-03-04 11:10:34 ERROR [main]i.s.logback.demo.Demo - ======
11:10:34,700 |-INFO in ReconfigureOnChangeTask(born:1551667606668) - Detected change in configuration files.
11:10:34,746 |-INFO in ReconfigureOnChangeTask(born:1551667606668) - Will reset and reconfigure context named [default]
11:10:34,700 |-INFO in ReconfigureOnChangeTask(born:1551667606668) - Detected change in configuration files.
11:10:34,746 |-INFO in ReconfigureOnChangeTask(born:1551667606668) - Will reset and reconfigure context named [default]
11:10:34,903 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/Users/momo/Documents/code/individualGithubProject/logbackmore/target/classes/logback.xml] 
11:10:34,903 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 6 seconds
11:10:34,904 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
11:10:34,905 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
11:10:34,925 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
11:10:34,925 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
11:10:34,930 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1631122623 - Will use gz compression
11:10:34,931 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1631122623 - Will use the pattern /var/log/admin-manage/log.%d{yyyy-MM-dd}.log for the active file
11:10:34,931 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/var/log/admin-manage/log.%d{yyyy-MM-dd}.log.gz'.
11:10:34,932 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
11:10:34,934 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Fri Mar 01 16:06:05 CST 2019
11:10:34,937 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: /Users/momo/Documents/temp/logs/rolling01.log
11:10:34,937 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [/Users/momo/Documents/temp/logs/rolling01.log]
11:10:34,938 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [indi] to ERROR
11:10:34,938 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [indi] to false
11:10:34,938 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[indi]
11:10:34,938 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
11:10:34,939 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
11:10:34,939 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
11:10:34,939 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@243a76fc - Registering current configuration as safe fallback point
2019-03-04 11:10:35 ERROR [main]i.s.logback.demo.Demo - error
2019-03-04 11:10:35 ERROR [main]i.s.logback.demo.Demo - ======
2019-03-04 11:10:36 ERROR [main]i.s.logback.demo.Demo - error
2019-03-04 11:10:36 ERROR [main]i.s.logback.demo.Demo - ======
2019-03-04 11:10:37 ERROR [main]i.s.logback.demo.Demo - error
2019-03-04 11:10:37 ERROR [main]i.s.logback.demo.Demo - ======

==== 讲解完毕 ====

你可能感兴趣的:(java,logback,scan)