Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
JSP - A mailing list about Java Server Pages specification and reference
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
How to use logging in Tomcat correctly (declare Logger Static or not) ?

How to use logging in Tomcat correctly (declare Logger Static or not) ?

2006-11-17       - By Mon Cab

 Back
Reply:     1     2     3  


>
> Good day
>
> I am having a hard time understanding how to use commons logging on
Tomcat.   The struts.apache.org suggest the following usage (presumably
for  business objects) (taken from:
> http://struts.apache.org/1.x/userGuide/building_controller.html )
>
>
>     package com.foo;
>                     // ...
>                     import org.apache.commons.logging.Log Source code of org.apache.commons.logging.Log;
>                     import org.apache.commons.logging.LogFactory Source code of org.apache.commons.logging.LogFactory;
>                     ...
>                     public class User {
>                     // ...
>                     private static Log log =
> LogFactory.getLog(User.class);
>                     // ...
>                     public void setBar(Bar bar) {                  
>
>                     log.trace("Setting bar to " + bar);
>                     this.bar = bar;
>                     }
>                     // ...
>                     }
>                
>
> The suggestion seems to be that it is OK to declare my Logger as a
> static variable in the business object.  This is ideal for me
> because,
> I will be accessing the Logger from both instance and static methods,
> and so I do not want to have to declare this as an instance variable.
>  
>
> However, I am wondering whether this is OK, given that my business
> objects will be being accessed from different servlet threads.  Can
> anyone tell me whether this is OK?, and if not, what is the correct
> way
> to do this?
>
> My second question is whether the same usage is valid for Action (or
servlet)  classes. I saw the following example, at
>
http://www.mobilefish.com/developer/struts/struts_quickguide_log4j.html
> but am not certain as to whether using a static variable would be OK
> here.  Would it?
>
> public class DemoServlet extends Servlet {
>
>       private static Log log =
> LogFactory.getLog("com.mobilefish.DemoAction");
>
>       public service  etc etc      {}

> }
>
> The commons logging documentation notes the following:
>
> Note that for application code, declaring the log member as "static"
> is
> more efficient as one Log object is created per class, and is
> recommended. However this is not safe to do for a class which may be
> deployed via a "shared" classloader in a servlet or j2ee container or
> similar environment. If the class may end up invoked with different
> thread-context-classloader values set then the member must not be
> declared static. The use of "static" should therefore be avoided in
> code within any "library" type project.
>
> I'm not clear as to what the above means, from a practical
> perspective
> in the context of a web applicaiton.  What does this mean in simple
> terms?
>
> Taken from:
>
http://jakarta.apache.org/commons/logging/guide.html#Configuring_Log4J
>
>
>
>
>
>  
>
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ______
__ __
> The all-new Yahoo! Mail beta
> Fire up a more powerful email and get things done faster.
> http://new.mail.yahoo.com
>
>




__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ______
__ __
Sponsored Link

$420k for $1,399/mo.
Think You Pay Too Much For Your Mortgage?
Find Out! www.LowerMyBills.com/lre

-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.