【发布时间】:2020-05-14 10:59:32
【问题描述】:
项目工件结构为:
test.ear
--lib - has all log4j2 jars core, web, bridge and JCL
--META-INF -- has app.xml, JBoss specific deployment XML, and manifest file
--a.war -- each war has web.xml with log4jConfiguration and Log4jServletContextListener specified.
--b.war
--c.war
战争使用 log4jConfiguration 创建上下文,即“classpath:test.xml”。我可以看到每场战争都使用我在 web.xml 中提供的 log4jContextName 创建上下文。我也有一些 cron,它们根据配置的时间间隔运行。当 crons 运行并且许多 JMS 进程运行时,我观察到日志文件没有填充日志(来自项目特定的类)。在浏览 log4j2 代码时,我了解到 log4j2 为每个类加载器创建一个上下文。在我的例子中,它为“test.ear”创建了一个上下文,默认为 error(DefaultContext),因为它无法找到默认的 log4j2.xml,因为我在类路径。 Log4jServletContextListener 没有捕捉到“test.ear”事件。
如何在 log4j2 为 ear 文件创建上下文时注入我的“classpath:test.xml”?由于我的项目可以同时部署到 WebSphere 和 JBoss,我期待着不是特定于服务器的建议。或者有没有办法以某种方式为所有战争和耳朵创建一个单一的上下文?我在同一台服务器的这个耳朵之外有不同的应用程序,所以我不能提供 -Dlog4j.configurationFile 的环境配置,因为其他应用程序有自己的 log4j2 xml。
【问题讨论】:
标签: spring jboss log4j websphere log4j2