You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by John Lindwall <JL...@Xifin.com> on 2001/04/13 02:29:06 UTC

Categories in Servlets

I understand why the log4j docs recommend declaring the Category as a static
variable in a "normal" class -- this reduces the overhead of creating the
object to a one-time event.
 
Is this also the best approach to take in a Servlet?  We have a heirarchy of
servlets in our product all of which descend from a base servlet class.  I
figured I would reduce the cost of retrofitting all of these servlets with
Category declarations by defining a Category in the base class and
initalizing it in init(), like so:
 
public class BaseServlet extends HttpServlet
{
 /** The category that this class will use for logging */
 protected static Category log = null;
...
 public void init(ServletConfig config)
     throws ServletException
 {
     super.init(config);
 
        // Initialize the logger using the subclass name as the category
name
       log = Category.getInstance(getClass().getName());
       ...
 
This should still be a low-cost approach since init() happens once. Does
this idea seem valid?
 
Thanks! 
----------------------------------------------------------------- 
John Lindwall                              mailto:johnl@xifin.com
<ma...@xifin.com>  
XIFIN                                      http://www.xifin.com
<http://www.xifin.com/>  
2233 Faraday Ave Ste A, Carlsbad CA 92008  (760) 804-0770 ext 16 

This message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender and destroy all copies of the original
message.

 

Re: Categories in Servlets

Posted by Ceki Gülcü <cg...@qos.ch>.
Hi John,

There is nothing special about servlets except that they get reloaded if the jar file or class files change. Getting a category instance is very fast. I would not waste my time trying to optimize category creation. Ceki

At 17:29 12.04.2001 -0700, John Lindwall wrote:
>I understand why the log4j docs recommend declaring the Category as a static variable in a "normal" class -- this reduces the overhead of creating the object to a one-time event.
> 
>Is this also the best approach to take in a Servlet?  We have a heirarchy of servlets in our product all of which descend from a base servlet class.  I figured I would reduce the cost of retrofitting all of these servlets with Category declarations by defining a Category in the base class and initalizing it in init(), like so:
> 
>public class BaseServlet extends HttpServlet
>{
> /** The category that this class will use for logging */
> protected static Category log = null;
>...
> public void init(ServletConfig config)
>     throws ServletException
> {
>     super.init(config);
> 
>        // Initialize the logger using the subclass name as the category name
>       log = Category.getInstance(getClass().getName());
>       ...
> 
>This should still be a low-cost approach since init() happens once. Does this idea seem valid?
> 
>Thanks! 
>----------------------------------------------------------------- 
>John Lindwall                              <ma...@xifin.com>mailto:johnl@xifin.com 
>XIFIN                                      <http://www.xifin.com/>http://www.xifin.com 
>2233 Faraday Ave Ste A, Carlsbad CA 92008  (760) 804-0770 ext 16 
>
>This message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender and destroy all copies of the original message.
> 

--
Ceki Gülcü     Web: http://qos.ch 
email: cgu@qos.ch or ceki_gulcu@yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org