Solved

loading multiple log4j properties

Posted on 2007-03-25
7
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses

626 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