log4j2在JBoss EAP 7上的EJB jar中记录代码 [英] log4j2 logging of code in EJB jar on JBoss EAP 7

查看:229
本文介绍了log4j2在JBoss EAP 7上的EJB jar中记录代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行以下操作:
将几个旧版应用程序从WebLogic移植到JBoss EAP 7.部分正在移植的组件是EJB。其他的是调用这些EJB的servlet应用程序。这些EJB部署在ejb-jar中。我知道我可以将这个整个东西包装成一个大的EAR文件,但是我们不想这样做。 servlet和EJB jar需要是可单独部署的组件。

I am doing the following: porting several legacy applications from WebLogic to JBoss EAP 7. Some of the components being ported are EJBs. Others are servlet apps that invoke these EJBs. These EJBs are deployed in ejb-jars. I know that I could wrap this whole thing into a big EAR file but we don't want to do that. The servlets and the EJB jars need to be separately deployable components.

然后是日志设置。我们正在使用log4j2,我们希望独立于JBoss日志记录设置。我创建了一个JBoss模块,其中包含所有具有适当依赖关系的log4j2 jar,日志记录工作。
servlet运行和记录,调用EJB,它们工作。

Then there is the logging setup. We are using log4j2 and we want to keep independent of the JBoss logging setup. I have created a JBoss module that contains all the log4j2 jars with the proper dependencies, and logging works. The servlet runs and logs, invokes the EJBs and they work.

唯一的问题是如何配置EJB的日志记录。在像Servlet这样的Web应用程序中,很容易,只需在web.xml中指定log4j日志记录配置文件即可。什么是ejb jar的模拟?我想不出一个办法。

The only problem is how to configure the EJB's logging. In a Web App like the servlet, it's easy, just specify the log4j logging configuration file in web.xml. What's the analog for an ejb jar? I couldn't think of a way.

我尝试了以下操作:将一个记录器/追加器添加到EJB包的servlet应用程序的配置中,并指定一个新文件。它不工作新的日志文件确实被创建,但没有写入到日志文件。应该有输出,但是没有,所以很明显当EJB运行时,它的LogManager没有使用servlet中指定的配置。

I tried the following: Add a logger/appender to the configuration of the servlet app for the EJB package and specify a new file. It doesn't work. The new logfile does get created but nothing gets written to the logfile. There should be output, but there isn't, so evidently when the EJB runs, its LogManager is not using the configuration specified in the servlet.

什么是正确的方式在JBoss EAP7上EJB jar中部署的EJB中指定log4j2配置?

What is the right way for specifying a log4j2 configuration in an EJB deployed in an EJB jar on JBoss EAP7?

推荐答案

我以前在这个空格中发布了一个涉及使用@postConstruct和@preDestroy方法来初始化和关闭LoggerContext对象的解决方案。

I had previously posted in this space a solution involving use of the @postConstruct and @preDestroy methods to initialize and shut down LoggerContext objects.

当我尝试将其扩展到无状态会话bean时,这个计划崩溃了。对于有状态的豆,它工作得很好。或者所以我想。最终我发现一个有关EJB限制的Oracle文档这暴露了我在做什么的弱点。我的解决方案包括EJB类的非最终静态LoggerContext成员。我找到了一种方法,使其成为最终的,这确实允许无国籍人的工作。但是我对我的做法越来越不满意。即使在有状况的情况下,我发现可能会在聚集环境中咬我的问题。

This plan fell apart when I tried to extend it to stateless session beans. It worked okay for Stateful Beans. Or so I thought. Eventually I found an Oracle document on EJB Restrictions which exposed the weaknesses in what I was doing. My "solution" included a non-final static LoggerContext member of the EJB class. I found a way to make it final, which did allow the stateless case to work. But I was increasingly dissatisfied with my approach. Even in the stateful case, I found issues that might bite me later in a clustered environment.

我现在所相信的是,我不应该做我正在尝试去做。

What I now come to believe is that I should not do what I was trying to do.

我甚至不能想象一个 static final LoggerContext 的复杂性,如果EJB被分发到群集中的另一台机器。像LoggerContext这样的对象不属于容器管理对象(如EJB)的静态成员。

I can't even imagine the complexity of what a static final LoggerContext would look like if an EJB were distributed to another machine in the cluster. Objects like LoggerContext don't belong as members, static or not, of container-managed objects like EJBs.

甚至不清楚EJB是什么的正确的实现技术我正在努力建设我的用例不是真正的事务性,所以EJB实现的情况不是很强,所以一个可能的路径完全远离EJB。

It's not even clear that EJBs are the right implementation technology for what I am trying to build. My use cases are not really transactional so the case for EJB implementation is not strong so one possible path leads away from EJBs altogether.

真正的消息是,如果EJB或其他指出容器管理的组件,最好使用容器提供的日志记录系统。我喜欢log4j2,但直到JBoss支持它,最好坚持使用容器提供的log4j1或其他一些框架。

The real message is that if EJBs or other container-managed components are indicated, it's probably best to use the container-provided logging system. I like log4j2, but until JBoss supports it, it's best to stick with container-provided log4j1 or some other framework.

这篇关于log4j2在JBoss EAP 7上的EJB jar中记录代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆