Results 1 to 3 of 3

Thread: Log4J shuts down too early

  1. #1
    Join Date
    Dec 2004
    Posts
    29

    Default Log4J shuts down too early

    I have written a small test to see how init and destroy methods are working in Spring Web Application.

    Here is a small bean I created:
    Code:
    public class InitDestroyTester {
      Logger logger = Logger.getLogger(InitDestroyTester.class);
    
      public void init() {
         logger.info("init() called");
      }
    
      public void destroy() {
         logger.info("destroy() called");
      }
    }
    
    <bean id="initDestroyTester" class="...InitDestroyTester" init-method="init" destroy-method="destroy" />
    When the WebApplicationContext is being initialized, everything's just fine, I can see log saying "init() called".

    However when webapp is removed from context (i.e. when I redeploy my webapp in Tomcat), I can't see "destroy() called" message in log.

    I figured out that it is only because Log4J was shutdown BEFORE InitDestroyTester could log something upon "destroy" call.

    How can I configure Log4J to be shutdown only after WebApplicationContext was disposed?
    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Leuven, Belgium
    Posts
    37

    Default

    Works for me, here are relevant parts of the logging :

    - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [initDestroyTester]; Root of BeanFactory hierarchy]
    - Creating shared instance of singleton bean 'initDestroyTester'
    - init() called
    ... reload ...
    - Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [initDestroyTester]; Root of BeanFactory hierarchy}
    - destroy() called
    - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [initDestroyTester]; Root of BeanFactory hierarchy]
    - Creating shared instance of singleton bean 'initDestroyTester'
    - init() called

    Do you use Log4jConfigListener ?
    see http://www.springframework.org/docs/...gListener.html

    Maarten

  3. #3
    Join Date
    Dec 2004
    Posts
    29

    Default

    Yes, I use the *Listener option. However it might be that my current version Tomcat is 2.3 Servlet version container, I'll try *Servlet option to see if it works better.

    Thanks for the hint!

Similar Threads

  1. Controlling log4j using Spring JMX and jmanage
    By kbaum in forum Management
    Replies: 13
    Last Post: Oct 14th, 2006, 09:13 AM
  2. Log4j, Commons Logging in JRun 4 problem
    By virgo_ct in forum Container
    Replies: 4
    Last Post: Jul 13th, 2005, 04:17 AM
  3. Replies: 4
    Last Post: Apr 6th, 2005, 12:07 PM
  4. Replies: 1
    Last Post: Dec 24th, 2004, 06:42 PM
  5. Stop Spring Logging
    By jgchristopher in forum Container
    Replies: 6
    Last Post: Dec 8th, 2004, 10:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •