Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

loading multiple log4j properties

Posted on 2007-03-25
7
Medium Priority
?
432 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 672 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 664 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 664 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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