Solved

loading multiple log4j properties

Posted on 2007-03-25
7
392 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
ID: 18789536
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
ID: 18789644
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
ID: 18790682
> 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
ID: 18790812
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
ID: 18791128
>>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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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:
This video teaches viewers about errors in exception handling.

860 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