Home arrow static arrow Java Programming [Archive] - Encapsulation of a logger (log4j ...)
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Encapsulation of a logger (log4j ...)
This topic has 3 replies on 1 page.

Posts:9
Registered: 11/13/01
Encapsulation of a logger (log4j ...)  
Jul 29, 2004 12:15 AM



 
Hi,

I want to encapsulate a logger , log4j for example. At first sigth, I wrote this :

public class MyObject
{
private Logger mylogger;
public MyObject(String myclass)
{
mylogger=Logger.getLogger(myclass);
}

public void debug(String message)
{
mylogger.debug(message);
}
....
}

The pb is : when you call debug, in the log file, I have the line in MyObject !!!!

Does anybody face this issue ?

thanks,

Ludovic
 

Posts:123
Registered: 5/24/04
Re: Encapsulation of a logger (log4j ...)  
Jul 29, 2004 1:48 AM (reply 1 of 3)



 
Why not:

public class Foo{private final static Logger logger = Logger.getLogger(Foo.class.getName());}
 

Posts:161
Registered: 8/7/97
Re: Encapsulation of a logger (log4j ...)  
Jul 29, 2004 3:45 AM (reply 2 of 3)



 
If i get it right you wonder why the linenumber in the log output show the linenumbers of your logger class and not the business code that calls your logger. If that is really your problem: what do you expect? How should log4j know that the code that is calling it (in this case it is you logger class) is not the code it should determine the linenumbers for.? And if this is not your problem then i have no idea what you are talking about ;-)
 

Posts:9
Registered: 11/13/01
Re: Encapsulation of a logger (log4j ...)  
Jul 29, 2004 11:43 PM (reply 3 of 3)



 
Thanks but I found the solution in the example of log4j !!!!! :

static String FQCN = MyObject.class.getName() + ".";
private Logger alogger = null;

public void debug(String message)
{
alogger.log(FQCN, Level.DEBUG, message, null);
}
 
This topic has 3 replies on 1 page.