Solved

loading multiple log4j properties

Posted on 2007-03-25
7
382 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 51
Python Assistance 7 80
simple java question 3 55
Java: anonymous class 4 17
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

785 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