简体   繁体   English

跨不同EE组件(REST / EJB)的独立日志记录

[英]Separate logging across different EE components (REST / EJB)

My purpose is to separate log4j configuration between REST and EJB in a JEE 5 web application (JBoss 5.1). 我的目的是在JEE 5 Web应用程序(JBoss 5.1)中在REST和EJB之间分离log4j配置。

For REST module, I use the ServletContextListener interface: 对于REST模块,我使用ServletContextListener接口:

public void contextInitialized(ServletContextEvent sce) {
     PropertyConfigurator.configure("logfile");
}

for EJB module, I'm using the StartupBeanManagement interface: 对于EJB模块,我正在使用StartupBeanManagement接口:

@Override
public void start() throws Exception {
    logger.info("starting configuration bean");
    final String env = System.getProperty("env");
    configureLog(logFilePrefix.replace("{0}", env));
}

However, if both modules are deployed on the same container, I can see log only only on dedicated REST log. 但是,如果两个模块都部署在同一容器上,则只能看到专用REST日志上的日志。

How I can separate logging between modules? 如何区分模块之间的日志记录?

Log4J holds its configuration at the classloader level. Log4J在类加载器级别保留其配置。 If two JEE modules share a classloader, they will have a single Log4J configuration at runtime. 如果两个JEE模块共享一个类加载器,则它们将在运行时具有单个Log4J配置。

In order to separate logging between modules, you need to: 为了分开模块之间的日志记录,您需要:

  • Configure your application server to use separate classloaders for separate modules (not all application servers allow this); 将您的应用程序服务器配置为对单独的模块使用单独的类加载器(并非所有应用程序服务器都允许这样做); and
  • Provide a separate Log4J configuration for every classloader. 为每个类加载器提供单独的Log4J配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM