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:[EMAIL PROTECTED]
XIFIN                                      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.

 

Reply via email to