Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j configuration in EAR

Tags:

java

log4j

ear

I have an EAR composed of ejb.jar archives.

Where can / should I place my log4j.xml configuration file in my EAR in order to configure log4j for the different EJBs?

Here is my following structure:

myEar
|-- myEjb1.jar
|-- myEjb2.jar
|-- myEjb3.jar
|-- lib
    | -- myLib1.jar
    | -- myLib2.jar

Thanks in advance!

like image 236
Blaise Gosselin Avatar asked Oct 03 '11 15:10

Blaise Gosselin


2 Answers

If log4j is used by different modules in the ear, it should be placed in a jar which is placed in the lib directory of the ear. But it is not very convenient since you will have to re-assemble your ear and redeploy it each time you change a log level.

Another option is to place the log4j config file in the folder and add that folder in the classpath of the ear. Most app server provides this feature (WebSphere for instance). It is less portable but more manageable: the config can be changed without redeploying the ear.

like image 68
Laurent Legrand Avatar answered Sep 18 '22 01:09

Laurent Legrand


Let's straighten this out: there's only one log4j for your enterprise application, regardless of how many EJBs it consists of. Similarly, there's only one configuration file. If you need to configure it for different EJBs, your option is to use appropriately named loggers in EJB's code and manage them in one log4j.xml.

Laurent has some interesting advice on where to put it (+1).

like image 27
MaDa Avatar answered Sep 22 '22 01:09

MaDa