This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes How to use Log4j implement singleton ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How to use Log4j implement singleton ?" Watch "How to use Log4j implement singleton ?" New topic
Author

How to use Log4j implement singleton ?

lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
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

Joined: Jan 10, 2002
Posts: 60732
    
  65

Why this was posted in the JSP forum is beyond me. Moving to Other Java APIs.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Log4j implement singleton ?
 
Similar Threads
Logging to one file from multiple java files
Obtaining access to Logger using a different Mechanism
How to encapsulate Logger info
Why do we need mulitple loggers? - Log4j
Good logging system for WebApp (Struts)