【问题标题】:One Tomcat two spring application (war) two seperate logging configurations一个Tomcat两个spring应用(war)两个单独的日志配置
【发布时间】:2016-12-17 19:19:33
【问题描述】:

如标题中所述,我有两个具有两种不同日志配置的应用程序。一旦我使用 springs logging.file 设置,我就无法分离两个应用程序的配置。

问题变得更加严重,因为一个应用正在使用 logback.xml,而一个应用正在使用 log4j.properties。

我尝试在一个应用程序中引入新的配置参数,我可以在其中设置 logback.xml 的路径,但我无法使新设置适用于应用程序中的所有日志记录。

 public static void main(String[] args) {
    reconfigureLogging();
    SpringApplication.run(IndexerApplication.class, args);
}

private static void reconfigureLogging() {
    if (System.getProperty("IndexerLogging") != null && !System.getProperty("IndexerLogging").isEmpty()) {
        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            // Call context.reset() to clear any previous configuration, e.g. default
            // configuration. For multi-step configuration, omit calling context.reset().
            System.out.println("SETTING: " + System.getProperty("IndexerLogging"));
            System.out.println("SETTING: " + System.getProperty("INDEXER_LOG_FILE"));
            context.reset();
            configurator.doConfigure(System.getProperty("IndexerLogging"));

        } catch (JoranException je) {
            System.out.println("FEHLER IN CONFIG");

        }
        logger.info("Entering application.");
    }
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    reconfigureLogging();
    return application.sources(applicationClass);
}

上面的代码以某种方式工作。但是,写入配置中指定的日志文件(${IndexerLogging} 指向的)的唯一日志条目是来自 logger.info("Entering application."); 的条目。 :(

我真的不喜欢将该代码附加到每个在应用程序中进行日志记录的类。

应用程序必须可以作为 tomcat 部署运行,也可以作为集成 tomcat 使用的 spring boot 应用程序运行。

知道如何将 ${IndexerLogging} 的路径设置为在该应用程序中首次配置日志记录时读取配置文件的路径吗?

【问题讨论】:

    标签: spring logging configuration log4j logback


    【解决方案1】:

    看看https://github.com/qos-ch/logback-extensions/wiki/Spring你可以配置logback配置文件来使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-26
      • 2020-01-03
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 2021-05-09
      • 2018-01-17
      • 2016-08-16
      相关资源
      最近更新 更多