You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sh...@ubs.com on 2002/12/09 10:54:59 UTC

RE: Re: Best Practices for Logging?(pne more addition..:-)))

Also I think one more thing that is important to do when using log4j in web 
application is to use NDC(nested diagnostic context).AS the web server is 
mulitthreaded, this becames very important so that u can keep track of the 
logging for a perticular user by addingd his session id in the NDC .Else the 
logging is absolutely meaning less as there will be so many log enreies by 
different threads for different requests and u cant see whats happening for a 
perticzular user.
More information about Nested Diagnostic context can be found at:
http://jakarta.apache.org/log4j/docs/manual.html


regards,
Shirish

-----Original Message-----
From: ekbush [mailto:ekbush@swbell.net]
Sent: Friday, December 06, 2002 9:38 PM
To: struts-user
Cc: ekbush
Subject: Re: Best Practices for Logging?


Sri Sankaran wrote:

>>-----Original Message-----
>>From: Matt Raible [mailto:matt@raibledesigns.com] 
>>Sent: Friday, December 06, 2002 1:34 PM
>>To: struts-user@jakarta.apache.org
>>Subject: Best Practices for Logging?
>>
>>
>>I'm wondering what is considered the best practice for logging using 
>>commons-logging in a Struts app.  My current approach is to 
>>have a Base 
>>class in every package that has the following:
>>
>>protected Log log =
>>         LogFactory.getLog("my.package.name");
>>
>>But I've noticed that some of the Struts examples have an instance of 
>>this in every class.  
>>    
>>
>Personally I prefer the class level.  This provides you with a finer grain of 
control.  However, I restrict it to only one per class and not one per object
>
>public class Foo {
>  private static Log log = LogFactory.getLog(Foo.class);
>  ..
>}
>
General consensus seems to be that this is the "best practice" approach. 
 You wind up with more loggers, but they give you very fine-grained 
control as Sri mentioned.  You can still set a log-level for a package, 
but you then also have the ability to manipulate the log-level on a per 
class basis too - so you can relaly "zoom-in" on things.

>>Is this recommended, so that logging 
>>can be done 
>>on a class level, as well as a package level?  Any thoughts/opinions 
>>are appreciated.
>>
It should be a static member as per what Sri shows (so you only have one 
per class).  Yes - it's so you can control logging on a package/class 
basis.

>>Thanks,
>>
>>Matt
>>    
>>
>Sri
>

-- 
Eddie Bush





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>