• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Log4j implement singleton ?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why this was posted in the JSP forum is beyond me. Moving to Other Java APIs.
bear
 
reply
    Bookmark Topic Watch Topic
  • New Topic