dharam
dharam

Reputation: 8096

Multiple log4j.properties files

This might not seem a valid question but I have a requirement here. Below is my project structure:

common (built as a jar)
module-1 (war, includes common.jar in its classpath)
module-2 (war, includes common.jar in its classpath)
module-3 (war, includes common.jar in its classpath)
module-4 (war, includes common.jar in its classpath)

The deployment is like below:

module-1 and module-2 is on one server and module-3 and module-4 on another.

The requirement is to have two separate log files(one for each server). So, the way to achieve this is put the log4j.properties (definitely with different names) in the common module and copy the required properties file to the respective server's conf folder.

I am not sure, if I can have the logging properties file with different names, if it is possible, please help me with a direction to do so.

EDIT To make this easier, if you anyone can tell me if I can use a different name for the log4j.properties file and how to load it to the server, I would be able to achieve the rest.

Thanks.

Upvotes: 2

Views: 7076

Answers (1)

dharam
dharam

Reputation: 8096

I finally fixed this issue, and yes there is a way of using a name different than log4j.properties for the log4j configuration properties file.

We can name it whatever we want say mylog4j.properties. For the JVM to pick this up we need to pass an argument to the JVM like below:

-Dlog4j.configuration=mylog4j.properties

When running applications using eclipse, you can do this by going to Run Configurations -> Arguments Tab -> VM Arguments and add the property -Dlog4j.configuration=mylog4j.properties

Upvotes: 5

Related Questions