亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

logback的addtivity屬性定義源碼解讀

 更新時(shí)間:2023年11月30日 09:17:11   作者:codecraft  
這篇文章主要為大家介紹了logback的addtivity屬性定義源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下logback的addtivity屬性

LoggerModel

ch/qos/logback/classic/model/LoggerModel.java

@PhaseIndicator(phase = ProcessingPhase.SECOND)
public class LoggerModel extends Model {
    private static final long serialVersionUID = 5326913660697375316L;
    String name;
    String level;
    String additivity;
    //......
}
LoggerModel定義了additivity屬性

LoggerAction

ch/qos/logback/classic/joran/action/LoggerAction.java

public class LoggerAction extends BaseModelAction {
    @Override
    protected boolean validPreconditions(SaxEventInterpretationContext ic, String name, Attributes attributes) {
        PreconditionValidator validator = new PreconditionValidator(this, ic, name, attributes);
        validator.validateNameAttribute();
        return validator.isValid();
    }
    @Override
    protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
            Attributes attributes) {
        LoggerModel loggerModel = new LoggerModel();
        String nameStr = attributes.getValue(NAME_ATTRIBUTE);
        loggerModel.setName(nameStr);
        String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
        loggerModel.setLevel(levelStr);
        String additivityStr = attributes.getValue(JoranConstants.ADDITIVITY_ATTRIBUTE);
        loggerModel.setAdditivity(additivityStr);
        return loggerModel;
    }
}
LoggerAction的buildCurrentModel方法會(huì)讀取additivity屬性,然后設(shè)置到loggerModel

LoggerModelHandler

ch/qos/logback/classic/model/processor/LoggerModelHandler.java

public class LoggerModelHandler extends ModelHandlerBase {
    Logger logger;
    boolean inError = false;
    //......
    @Override
    public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
        inError = false;
        LoggerModel loggerModel = (LoggerModel) model;
        String finalLoggerName = mic.subst(loggerModel.getName());
        LoggerContext loggerContext = (LoggerContext) this.context;
        logger = loggerContext.getLogger(finalLoggerName);
        String levelStr = mic.subst(loggerModel.getLevel());
        if (!OptionHelper.isNullOrEmpty(levelStr)) {
            if (JoranConstants.INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) {
                if(Logger.ROOT_LOGGER_NAME.equalsIgnoreCase(finalLoggerName)) {
                    addError(ErrorCodes.ROOT_LEVEL_CANNOT_BE_SET_TO_NULL);
                } else {
                    addInfo("Setting level of logger [" + finalLoggerName + "] to null, i.e. INHERITED");
                    logger.setLevel(null);
                }
            } else {
                Level level = Level.toLevel(levelStr);
                addInfo("Setting level of logger [" + finalLoggerName + "] to " + level);
                logger.setLevel(level);
            }
        }
        String additivityStr = mic.subst(loggerModel.getAdditivity());
        if (!OptionHelper.isNullOrEmpty(additivityStr)) {
            boolean additive = OptionHelper.toBoolean(additivityStr, true);
            addInfo("Setting additivity of logger [" + finalLoggerName + "] to " + additive);
            logger.setAdditive(additive);
        }
        mic.pushObject(logger);
    }
    //......
}
LoggerModelHandler的handle方法會(huì)讀取additivityStr,然后設(shè)置到logger中

Logger

ch/qos/logback/classic/Logger.java

public final class Logger
        implements org.slf4j.Logger, LocationAwareLogger, LoggingEventAware, AppenderAttachable<ILoggingEvent>, Serializable {
    //......
    /**
     * The parent of this category. All categories have at least one ancestor which
     * is the root category.
     */
    transient private Logger parent;
    /**
     * Additivity is set to true by default, that is children inherit the appenders
     * of their ancestors by default. If this variable is set to <code>false</code>
     * then the appenders located in the ancestors of this logger will not be used.
     * However, the children of this logger will inherit its appenders, unless the
     * children have their additivity flag set to <code>false</code> too. See the
     * user manual for more details.
     */
    transient private boolean additive = true;
    //......
    public void callAppenders(ILoggingEvent event) {
        int writes = 0;
        for (Logger l = this; l != null; l = l.parent) {
            writes += l.appendLoopOnAppenders(event);
            if (!l.additive) {
                break;
            }
        }
        // No appenders in hierarchy
        if (writes == 0) {
            loggerContext.noAppenderDefinedWarning(this);
        }
    }
    void recursiveReset() {
        detachAndStopAllAppenders();
        localLevelReset();
        additive = true;
        if (childrenList == null) {
            return;
        }
        for (Logger childLogger : childrenList) {
            childLogger.recursiveReset();
        }
    }
    //......
}
Logger的callAppenders方法會(huì)先打印自己的appender,然后逐層遍歷parent進(jìn)行打印,若additive為false則不通過parent的appender打印

小結(jié)

logback的Logger提供了addtivity屬性,默認(rèn)為true,即除了自己appender,還會(huì)通過parent的appender進(jìn)行打印,設(shè)置為false則不通過parent的appender進(jìn)行打印。

以上就是logback的addtivity屬性源碼解讀的詳細(xì)內(nèi)容,更多關(guān)于logback addtivity屬性的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • SpringBoot集成Redis向量數(shù)據(jù)庫實(shí)現(xiàn)相似性搜索功能

    SpringBoot集成Redis向量數(shù)據(jù)庫實(shí)現(xiàn)相似性搜索功能

    Redis?是一個(gè)開源(BSD?許可)的內(nèi)存數(shù)據(jù)結(jié)構(gòu)存儲(chǔ),用作數(shù)據(jù)庫、緩存、消息代理和流式處理引擎,向量檢索的核心原理是通過將文本或數(shù)據(jù)表示為高維向量,并在查詢時(shí)根據(jù)向量的相似度進(jìn)行搜索,本文給大家介紹了SpringBoot集成Redis向量數(shù)據(jù)庫實(shí)現(xiàn)相似性搜索功能
    2024-09-09
  • springboot 無法掃描到父類模塊中Bean的原因及解決

    springboot 無法掃描到父類模塊中Bean的原因及解決

    這篇文章主要介紹了springboot 無法掃描到父類模塊中Bean的原因及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Pattern.compile函數(shù)提取字符串中指定的字符(推薦)

    Pattern.compile函數(shù)提取字符串中指定的字符(推薦)

    這篇文章主要介紹了Pattern.compile函數(shù)提取字符串中指定的字符,使用的是Java中的Pattern.compile函數(shù)來實(shí)現(xiàn)對(duì)指定字符串的截取,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-12-12
  • java swing實(shí)現(xiàn)簡單計(jì)算器界面

    java swing實(shí)現(xiàn)簡單計(jì)算器界面

    這篇文章主要為大家詳細(xì)介紹了java swing實(shí)現(xiàn)簡單計(jì)算器界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Java滾動(dòng)數(shù)組計(jì)算編輯距離操作示例

    Java滾動(dòng)數(shù)組計(jì)算編輯距離操作示例

    這篇文章主要介紹了Java滾動(dòng)數(shù)組計(jì)算編輯距離操作,涉及java字符串與數(shù)組的遍歷、計(jì)算、轉(zhuǎn)換等相關(guān)操作技巧,需要的朋友可以參考下
    2019-12-12
  • java8如何根據(jù)list對(duì)象中的屬性過濾篩選

    java8如何根據(jù)list對(duì)象中的屬性過濾篩選

    這篇文章主要介紹了java8如何根據(jù)list對(duì)象中的屬性過濾篩選,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • springboot如何接收application/x-www-form-urlencoded類型的請(qǐng)求

    springboot如何接收application/x-www-form-urlencoded類型的請(qǐng)求

    這篇文章主要介紹了springboot如何接收application/x-www-form-urlencoded類型的請(qǐng)求,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • java中字符串與日期的轉(zhuǎn)換實(shí)例

    java中字符串與日期的轉(zhuǎn)換實(shí)例

    java中字符串與日期的轉(zhuǎn)換實(shí)例,需要的朋友可以參考一下
    2013-05-05
  • 使用Jitpack發(fā)布開源Java庫的詳細(xì)流程

    使用Jitpack發(fā)布開源Java庫的詳細(xì)流程

    這篇文章主要介紹了使用Jitpack發(fā)布開源Java庫的詳細(xì)流程,本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • 使用Springboot整合Apollo配置中心

    使用Springboot整合Apollo配置中心

    這篇文章主要介紹了使用Springboot整合Apollo配置中心的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07

最新評(píng)論