如何在 Glassfish 3 中为每个已部署的应用程序配置 log4j?
我正在尝试使用 log4j 来处理在 Glassfish 3 下运行的 Web 服务的日志。我见过的大多数使用 log4j 和 Glassfish 的指南都希望我搞乱 Glassfish 全局设置,我想避免这种情况因为每个 Glassfish 实例都会部署多个应用程序。
有没有什么方法可以让 Glassfish 在部署 Web 服务时执行一段代码,从而允许我调用 DOMConfigurator 并使用 XML 文件设置 log4j?
感谢您的帮助!
编辑:答案是将 log4j.xml 文件放在 WEB-INF/classes 中。在我们的例子中,看起来 log4j 仍未配置,但日志记录实际上仍然按预期工作。
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.
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?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。您所需要做的就是使用您正在部署的组件来部署 log4j 配置;只要父类加载器中没有引用 log4j,log4j 就会使用本地范围的配置。
在这种情况下,Glassfish 的全局设置根本不会被考虑在内。
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.
Glassfish' global settings won't factor in at all in that case.