class/method level logging?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Manesh_Sankarankutty
Posted On:   Monday, November 10, 2003 02:29 AM

Can we configure log4j to log in the class level , for instance as I have a class 'A' as well as class 'B' in the package 'com.xyz.cls'. I want an appender 'appenderOne' to be used for class 'A' and 'appenderTwo' to be used for class 'B'. Benefit here is I may require logging from class 'A' at a time and I may want to switch off loggin from class 'B' but all in the same levels of logging. Is this possible? If yes, how do we do this? Else, are there any work arounds? Similarly.. do we have an option to ON/OFF logging in method level ? Just wondering if that's possible. There are cases where we have felt such a requirement too but yes, it may be a bit too complex for the lo   More>>

Can we configure log4j to log in the class level , for instance as I have a class 'A' as well as class 'B' in the package 'com.xyz.cls'.


I want an appender 'appenderOne' to be used for class 'A' and 'appenderTwo' to be used for class 'B'. Benefit here is I may require logging from class 'A' at a time and I may want to switch off loggin from class 'B' but all in the same levels of logging.


Is this possible?
If yes, how do we do this?
Else, are there any work arounds?


Similarly.. do we have an option to ON/OFF logging in method level ? Just wondering if that's possible. There are cases where we have felt such a requirement too but yes, it may be a bit too complex for the log4j internally.

   <<Less

Re: class/method level logging?

Posted By:   Anonymous  
Posted On:   Monday, November 10, 2003 03:26 AM

Yes. Simply create (configure) another logger and ask for that in your classes. I would do some like that:


...




















public class ClassA {
protected org.apache.log4j.Logger log = org.apache.log4j.Logger.getInstance( this.getClass() );
}

public class ClassB {
public void methodOne() {
Logger log = Logger.getInstance( this.getClass().getName() + "$methodOne()" );
}
}
About | Sitemap | Contact