Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure multiple log4j for different wars in a single EAR?

I have a EAR with structures like:

APP.ear 
- APP1.war
    - WEB-INF/classes/log4j.properties
- APP2.war
    - WEB-INF/classes/log4j.properties
- app1-ejb.jar
- app2-ejb.jar
- log4j.jar
- spring.jar
- commons-lang.jar (...and other jar)

I want each WAR to have their own application log. But it seems the above configuration does not work. Log for APP1 and APP2 goes to APP1's log. Is there anyway to create separate app logs?

like image 663
jackysee Avatar asked Apr 18 '09 04:04

jackysee


People also ask

Where should I set log4j2 formatMsgNoLookups to true?

You can do this: %m{nolookups} in the layout. {nolookups} is how you set the property log4j2. formatMsgNoLookups=true within the configuration XML content.

What is log4j default configuration?

Log4j will provide a default configuration if it cannot locate a configuration file. The default configuration, provided in the DefaultConfiguration class, will set up: A ConsoleAppender attached to the root logger. A PatternLayout set to the pattern "%d{HH:mm:ss.

Does JBoss use log4j?

JBoss AS uses log4j as logging framework. This tutorial will show how to configure log4j service in your jBoss application server and also how to create a custom configuration which can be deployed along with your application. Log4j is a flexible open source project from Apache.


2 Answers

It turns out that it's impossible due to the classloader. The classloader hierarchy is like:

Application classloader -> Ejb classloader -> war classloader

To have a sepearte log for individual war, one can put log4j.jar inside war and let the log4j uses the war classloader. But as both app1-ejb.jar and app2-ebj.jar also need to use log4j, the log4j.jar can only be placed at the top level. So the log4j is on application classloader level.

I can specify a single log4j config to log different package to different files. But for the common library like spring, the log cannot be sepearted.

like image 137
jackysee Avatar answered Nov 11 '22 11:11

jackysee


The reason it didnt work because the log4j is present at the root location, instead let each war have a Log4j.jar in its WEB-INF/lib directory and remove the log4j.jar from the root.

For more info on this refer my blog article on this http://techcrawler.wordpress.com/

like image 32
Sudhakar Avatar answered Nov 11 '22 12:11

Sudhakar