Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to implement singleton using Log4j?

843836Nov 20 2003 — edited Nov 21 2003
Hi everyone:

I want to implement a singleton pattern while using Log4j.But what puzzle me is it need a Class as its argument while create a Logger object.For example:

Logger log=Logger.getLogger(XXX.class);
But the singleton pattern is:
///////////////////////////////////logFactory.java//////////////////
public class logfactory{
private static Logger log=null;
private logfactory(){
log=Logger.getLogger(???)
}

How I get the argument(XXX.class) to the constructor?

If I change the code to :
/////////////////////////////////////public class logfactory{
private static Logger log=null;
private logfactory(Class classname){
log=Logger.getLogger(???)
}
It can't implement what I want to get.How to use singleton in Log4j?
Thks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2003
Added on Nov 20 2003
2 comments
562 views