【问题标题】:show which file Logback is reading and in what file path?显示 Logback 正在读取哪个文件以及在哪个文件路径中?
【发布时间】:2014-08-29 20:13:56
【问题描述】:

如果 Logback 正在读取一些 logback.xml 文件,是否可以显示它正在读取哪个文件以及在哪个文件路径中?

我在使用 logback 时遇到问题,我想到了一个想法,也许一些第三方 jar 文件提供了自己的 logback.xml,而不是我的,它的文件被 Logback 用作配置文件。

如果我在内部了解 Logback 将哪个文件和路径用作配置文件,我可能会提出一些解决方案,以便最终使用我自己的 logback.xml 配置。

【问题讨论】:

    标签: java slf4j logback


    【解决方案1】:

    跟着源码走,终于到这里了:

    public static void printLogConfigUrl() {
    
        ch.qos.logback.core.joran.spi.ConfigurationWatchList wl =
                ch.qos.logback.core.joran.util.ConfigurationWatchListUtil.getConfigurationWatchList(
                (ch.qos.logback.classic.LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory());
        System.out.println(wl.getMainURL());
    }
    

    作为参考,我从ContextInitializer 开始,让GenericConfiguratorConfigurationWatchListUtil 上图所示。

    【讨论】:

      【解决方案2】:

      感谢@vanOekel,我找到了一种方法来发出用于配置的 Logback 文件;

      LoggerContext loggerContext = ((ch.qos.logback.classic.Logger) logger).getLoggerContext();
      System.out.println(ConfigurationWatchListUtil.getMainWatchURL(loggerContext));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-10
        • 1970-01-01
        • 2017-01-27
        • 1970-01-01
        • 2012-06-15
        • 2022-08-18
        相关资源
        最近更新 更多