Solved

loading multiple log4j properties

Posted on 2007-03-25
7
361 Views
Last Modified: 2010-05-19
Hi,

I need to load three log4j.properties files.
say log4j1.properties, log4j2.properties, log4j3.properties
which will be used by different classes
MyLogger1.java, MyLogger2.java, MyLogger3.java

How do i do that? does second log4j overrides first one?

Thanks
0
Comment
Question by:bhushan_geete
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Try

Properties combinedProps = new Properties();

// load all these separately: log4j1.properties, log4j2.properties, combinedProps.putAll(log4j1Props);
combinedProps.putAll(log4j2Props);
combinedProps.putAll(log4j3Props);

PropertyConfigurator.configure(combinedProps);
0
 

Author Comment

by:bhushan_geete
Comment Utility
I will be loading it at different time and places, so how can it be managed.
I have no control on other log4j.properties as it it managed by someone else.
0
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 168 total points
Comment Utility
> I have no control on other log4j.properties as it it managed by someone else.

Are you trying to say that you want to load different log4j.properties file on the application? log4j.properties file is loaded at the class level and hence there would be only one log4j.properties file effective at a given time. But, if you want to load multiple log4j.properties, you need to use classloaders.
0
 
LVL 12

Assisted Solution

by:keyurkarnik
keyurkarnik earned 166 total points
Comment Utility
Instead of doing it that way - using multiple properties file, you should use log4j the way ithas been intended.
You should create just one file with different loggers as required. (And by this I dont mean just combining the files - design andconstruct the file as needed - for each logger)
There is nothing that you cant do with a single props file for which you would need multiple files.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 166 total points
Comment Utility
>>I will be loading it at different time and places, so how can it be managed.

No quite sure what you mean by that

>>I have no control on other log4j.properties as it it managed by someone else.

You don't need control - you just need to be able to read the files
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now