I'm trying to use log4j to handle the logs for a web-service which is running under Glassfish 3. Most of the guides I've seen using log4j with Glassfish want me to mess around with Glassfish global settings, which I want to avoid as there will be more than one application deployed per instance of Glassfish.
我正在尝试使用log4j来处理在Glassfish 3下运行的Web服务的日志。我看到使用带有Glassfish的log4j的大多数指南都希望我搞砸Glassfish全局设置,我想避免因为每个Glassfish实例都会部署多个应用程序。
Is there any way for me to have Glassfish execute a piece of code when my web service is deployed which will allow me to call DOMConfigurator and set up log4j using my XML file?
在部署我的Web服务时,有没有办法让Glassfish执行一段代码,这将允许我调用DOMConfigurator并使用我的XML文件设置log4j?
Thanks for any help!
谢谢你的帮助!
EDIT: The answer is to place the log4j.xml file in WEB-INF/classes. In our case, it looks as if log4j remains un-configured, but logging does still actually work as expected.
编辑:答案是将log4j.xml文件放在WEB-INF / classes中。在我们的例子中,看起来log4j仍然未配置,但是日志记录确实仍然按预期工作。
1 个解决方案
#1
5
Yes. All you need to do is deploy the log4j configuration with the component you're deploying; log4j will use the locally-scoped configuration as long as it's not being referenced in a parent classloader.
是。您需要做的就是使用您正在部署的组件部署log4j配置; log4j将使用本地范围的配置,只要它没有在父类加载器中引用。
Glassfish' global settings won't factor in at all in that case.
在这种情况下,Glassfish的全球环境根本不会考虑因素。
#1
5
Yes. All you need to do is deploy the log4j configuration with the component you're deploying; log4j will use the locally-scoped configuration as long as it's not being referenced in a parent classloader.
是。您需要做的就是使用您正在部署的组件部署log4j配置; log4j将使用本地范围的配置,只要它没有在父类加载器中引用。
Glassfish' global settings won't factor in at all in that case.
在这种情况下,Glassfish的全球环境根本不会考虑因素。