tomcat7中如何从系统环境中读取logback配置文件

How to read logback configuration file from system environment in tomcat 7

先讲故事:

我们有 2 个 j2ee web 应用程序 AAA 和 BBB,我们想将它们放在同一台服务器上。

现在他们的 class 路径中都有 logback.xml,对于 maven 项目,它位于 /src/main/resources 中。

我们想把所有的配置文件放在一个目录下,比如${app_home},让web应用自己找到自己的配置文件。

就像我们把 AAA_logback.xml 和 BBB_logback.xml 放到 ${app_home} 中,让 web 应用程序自动找到它们。

我们使用 Tomcat 7 来部署 Web 应用程序,如果我们要实现这一点,我们是否需要对 Tomcat 7 配置进行任何更改?

还有一个类似的问题: How to read Logback configuration file from path outside the war file?

我希望我用我糟糕的英语问清楚我的问题。

我建议您将原始 logback.xml 保留在各自的类路径中,并包含 ${app_home}/...

中的实际内容

参见 www.logback.qos.ch/manual/configuration.html#fileInclusion

通过这种方式可以为不同的应用指定不同的文件。