設(shè)置了 scanPeriod 之后,過了好長時(shí)間,都不生效,后來 debug 代碼。發(fā)現(xiàn)了下面這段。
private volatile long mask = 0xF; @Override public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { if (!isStarted()) { return FilterReply.NEUTRAL; } // for performance reasons, skip change detection (MASK-1) times out of MASK. // Only once every MASK calls is change detection code executed // Note that MASK is a variable itself. if (((invocationCounter++) & mask) != mask) { return FilterReply.NEUTRAL; } long now = System.currentTimeMillis(); synchronized (configurationWatchList) { updateMaskIfNecessary(now); if (changeDetected(now)) { // Even though reconfiguration involves resetting the loggerContext, // which clears the list of turbo filters including this instance, it is // still possible for this instance to be subsequently invoked by another // thread if it was already executing when the context was reset. disableSubsequentReconfiguration(); detachReconfigurationToNewThread(); } } return FilterReply.NEUTRAL; }
這行 if (((invocationCounter++) & mask) != mask) {
mask = 0xf,其實(shí)要每循環(huán) 0xf 次,也就是 15 次,才會去 check 一次是否要更新,也就是說,不管過了多久,如果沒到這 15 次,也不會去檢查是否更新配置。
也就是說,我多打幾次 log,配置文件就生效了。