Results 1 to 2 of 2

Thread: Can't shutdown Log4J in Tomcat with Log4jConfigListener

  1. #1
    Join Date
    Oct 2004
    Posts
    15

    Default Can't shutdown Log4J in Tomcat with Log4jConfigListener

    Hi ng,

    I've been having some serious problems using Log4J on tomcat. We're actually using Sun One 7 but its actually bundled with tomcat.

    So, the problem i've been having is in trying to properly shutdown log4j, if i try to redeploy on a running server i get a bind exception from log4j not being cleaned up and the port being closed, here's the exception:

    Code:
    [20/Dec/2004:10:03:22] INFO (  168): CORE3276: Installing a new configuration
    [20/Dec/2004:10:03:22] INFO (  168): WEB0100: Loading web module [webtest] in virtual server [server1] at [/webtest]
    [20/Dec/2004:10:03:24] WARNING (  168): CORE3283: stderr: log4j:ERROR exception setting timeout, shutting down server socket.
    [20/Dec/2004:10:03:25] WARNING (  168): CORE3283: stderr: java.net.BindException: Address already in use: JVM_Bind
    [20/Dec/2004:10:03:25] WARNING (  168): CORE3283: stderr: 	at java.net.PlainSocketImpl.socketBind(Native Method)
    [20/Dec/2004:10:03:25] WARNING (  168): CORE3283: stderr: 	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:331)
    [20/Dec/2004:10:03:25] WARNING (  168): CORE3283: stderr: 	at java.net.ServerSocket.bind(ServerSocket.java:318)
    &#91;20/Dec/2004&#58;10&#58;03&#58;25&#93; WARNING &#40;  168&#41;&#58; CORE3283&#58; stderr&#58; 	at java.net.ServerSocket.<init>&#40;ServerSocket.java&#58;185&#41;
    &#91;20/Dec/2004&#58;10&#58;03&#58;25&#93; WARNING &#40;  168&#41;&#58; CORE3283&#58; stderr&#58; 	at java.net.ServerSocket.<init>&#40;ServerSocket.java&#58;97&#41;
    &#91;20/Dec/2004&#58;10&#58;03&#58;25&#93; WARNING &#40;  168&#41;&#58; CORE3283&#58; stderr&#58; 	at org.apache.log4j.net.SocketHubAppender$ServerMonitor.run&#40;SocketHubAppender.java&#58;315&#41;
    &#91;20/Dec/2004&#58;10&#58;03&#58;25&#93; WARNING &#40;  168&#41;&#58; CORE3283&#58; stderr&#58; 	at java.lang.Thread.run&#40;Thread.java&#58;534&#41;
    I'm using the Log4jConfigListener but it seems unable to close log4j. I think there is some problem with tomcat not cleaning up the classloader and static references sticking around after the web app has been undeployed. Has anyone come accross a similar problem or have any idea on how i can work around this?

    Also on a different point there is another problem when i try to redeploy in sunone 7 using the Log4jConfigListener, for some reason the webAppRootKey context parameter is not removed so when a new deployement is deployed and exploded into a new unique directory by sunone it throws an exception about the name already being in use. Any suggestions?

    btw heres the test web.xml:

    Code:
    <web-app>
    	<display-name>WebTest</display-name>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    		</param-value>
    	</context-param>
    	 <context-param>
    		<param-name>log4jConfigLocation</param-name>
    	<param-value>WEB-INF/classes/log4j.properties</param-value>
    	</context-param>
    	<context-param>
    		<param-name>webAppRootKey</param-name>
    		<param-value>webtest.root</param-value>
    	</context-param> 
    	<listener>
    		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    </web-app>
    thanks,
    cam[/code]

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

    Default

    Regarding your 2nd question, I had similar problem and since I do not use the webAppRootKey system property I decided to write my own very simple ServletContextListener :

    Code:
    public void contextDestroyed&#40;ServletContextEvent event&#41; &#123;
        ServletContext context = event.getServletContext&#40;&#41;;
        LogFactory.getLog&#40;getClass&#40;&#41;&#41;.debug&#40;"shutting down log4j for "+ context.getServletContextName&#40;&#41;&#41;;
    		Log4jWebConfigurer.shutdownLogging&#40;context&#41;;
    	&#125;
    see warning in http://www.springframework.org/docs/...onfigurer.html

    IMHO, setting the system property should be optional in Log4jWebConfigurer.

    Maarten

Similar Threads

  1. Spring + Quartz + Tomcat = no shutdown
    By ahumphr in forum Container
    Replies: 7
    Last Post: Jul 5th, 2011, 11:45 AM
  2. Tomcat 5.5, Log4J, Spring
    By KnisterPeter in forum Web
    Replies: 2
    Last Post: Jul 9th, 2006, 01:17 PM
  3. Log4j blues, Tomcat 5.030 in a Win Box.
    By gfaerman in forum Container
    Replies: 4
    Last Post: Oct 13th, 2005, 06:29 PM
  4. Tomcat WAR, log4j
    By br14n in forum Web
    Replies: 0
    Last Post: Aug 19th, 2005, 12:31 AM
  5. Replies: 0
    Last Post: Apr 7th, 2005, 12: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
  •