怎样载入指定路径的Logback.xml

今天想外置logback.xml,谢了例如以下代码

     File logbackFile = new File("./conf/logback.xml");
        if (logbackFile.exists()) {
            LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(lc);
            lc.reset();
            try {
                configurator.doConfigure(logbackFile);
            }
            catch (JoranException e) {
                e.printStackTrace(System.err);
                System.exit(-1);
            }
        }

可是老师不依照策略输出,整了两小时,開始以为lc.reset()放错位置了,可是后来发现是我的JoranConfigurator这个类引用错了,正确的类路径是

ch.qos.logback.classic.joran.JoranConfigurator

可是我错误引用了

ch.qos.logback.access.joran.JoranConfigurator

哭死的节奏,debug到代码里面怎么就说没有处理contextName的Action,原来ch.qos.logback.access仅仅处理主要的配置,上下文这个处理在logback-classic里面,究其原因是由于eclipse的自己主动提示,我下意识就选了第一个,写下这篇博客这也算自我检讨吧.

【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/zhchoutai/p/8522845.html