简体   繁体   中英

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).

For REST module, I use the ServletContextListener interface:

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

for EJB module, I'm using the StartupBeanManagement interface:

@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.

How I can separate logging between modules?

Log4J holds its configuration at the classloader level. If two JEE modules share a classloader, they will have a single Log4J configuration at runtime.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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