Announcement Announcement Module
Collapse
No announcement yet.
Can't shutdown Log4J in Tomcat with Log4jConfigListener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X