First, it's not a good idea to subclass the Logger class. Better write a 
wrapper if you want to centralize some logging policies.

Your problem can be solved if you do not call the super.info() etc., but the 
generic log(String callerFQCN, Priority level, Object message, Throwable t) 
method. The first parameter you fill with "this.getClass().getName()". The code 
inside log4j which calculates the location info looks up within the call 
hierarchie, stripping all classes away until (including) the given one by 
callerFQCN. Like this you will obtain the location where you have called your 
wrapper class.

Heri

> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] Behalf Of kaustuva mukherjee
> Sent: Monday, February 06, 2006 4:47 PM
> To: log4j-user@logging.apache.org
> Subject: problem getting location info from client
> 
> 
> I have subclassed the Logger class of log4j. The problem i 
> have is that how to 
> get the location information when i use the subclass of the 
> Logger class i.e 
> XXXLogger. 
> e.g I have the following client code where i am logging using 
> XXXLogger
> 
> public class SomeClient{
> 
> XXXLogger logger = (XXXLogger) XXXLogger.getLogger(some.transaction);
> 
> public someClientMethod(){
> 
> logger.info( param1, message, param3 [] );
> 
> }
> 
> public class XXXLogger extends Logger {
> 
> public void info(int param1, String Msg,  Object[] params) {
> 
> //do something here
> 
> this.info(message);
> 
> }
> 
> public class XXXLayout extends Layout 
> 
> public String format(LoggingEvent event) {
> 
>    this.event = event;
>    return convertToText();  
>    
>    }
> 
>   private String convertToText() {
> LocationInfo locInfo= event.getLocationInformation();
>     String lineNumber =locInfo.getLineNumber(); 
>     String methodName =locInfo.getMethodName();
>     String className = locInfo.getClassName();
>     String message = (String) event.getMessage();
> :
> :  
> In the output of my custom layout i am getting the method 
> name and className of 
> XXXLogger but i want to get the location info of the SomeClient !! 
> Do you know how this could be resolved?
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to