Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Log4j implement singleton ?

 
lyo Yashnoo
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(???)
}
public static Logger getInstance(){
................what code?...... }
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.How to use singleton in Log4j?
Thks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why this was posted in the JSP forum is beyond me. Moving to Other Java APIs.
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic