4 Replies Latest reply on Mar 26, 2013 6:20 AM by Matti Hansson

    Unable to log to console with log4j

    Matti Hansson Newbie

      Hi!

      I have a web service with log4j configuration outside of the war file. Loggin to a file using org.apache.log4j.DailyRollingFileAppender works fine, but switching to a org.apache.log4j.ConsoleAppender causes everything to freeze while using 100% CPU. This is our setup:

       

      pom.xml

      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <exclusions>
          <exclusion>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
          </exclusion>
          <exclusion>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <version>1.6.1</version>
      </dependency>
      

       

      jboss-deployment-structure.xml

      <jboss-deployment-structure>
        <deployment>
          <dependencies>
            ...
          </dependencies>
          <exclusions>
            <module name="org.apache.log4j"/>
            <module name="org.slf4j"/>
            <module name="org.slf4j.jcl-over-slf4j"/>
          </exclusions>
        </deployment>
      </jboss-deployment-structure>
      

       

      web.xml

      <display-name>my-service-${version}</display-name>
      
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <listener>
        <!-- Extends org.springframework.web.util.Log4jConfigListener, exports display-name as system property "webapp-name"  -->
        <listener-class>com.myservice.log.Log4jConfigListener</listener-class>
      </listener>
      
      <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>file:${settings.home}/my-service-logging-${version}.xml</param-value>
      </context-param>
      

       

      my-service-logging-1.0-SNAPSHOT.xml in C:\settings\ ("settings.home")

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
      
        <!-- APPENDERS -->
        <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %-5p %m at %C.%M(%F:%L)%n" />
          </layout>
        </appender>
        
        <!--<appender name="RollingFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
          <param name="File" value="${jboss.server.log.dir}/${webapp-name}.log"/>
          <param name="DatePattern" value="'.'yyyy-MM-dd"/>
          <param name="Append" value="false"/>
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %-5p %m at %C.%M(%F:%L)%n"/>
          </layout>
        </appender>-->
      
        <logger name="com.myservice">
          <level value="debug"/>
        </logger>
      
        <logger name="org.springframework">
          <level value="debug"/>
        </logger>
      
        <logger name="org.apache">
          <level value="debug"/>
        </logger>
      
        <!-- CONFIG -->
        <root>
          <priority value="debug" />
          <appender-ref ref="ConsoleAppender" />
          <!-- <appender-ref ref="RollingFileAppender" /> -->
        </root>
      </log4j:configuration>
      

       

      So, when I use the RollingFileAppender everything works fine. If I try to use the ConsoleAppender, when deploying, the last bit of output I get is this:

       

      14:57:45,522 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/my-service-1.0-SNAPSHOT]] Initializing log4j from [file:C:/settings/my-service-logging-1.0-SNAPSHOT.xml]
      14:57:45,600 FINE  [javax.enterprise.resource.webcontainer.jsf.config] ConfigureListener.contextInitialized(/my-service-1.0-SNAPSHOT)
      14:57:45,600 INFO  [stdout] 2013-03-22 14:57:45,600 DEBUG ConfigureListener.contextInitialized(/my-service-1.0-SNAPSHOT) at ?.?(?:?)
      

       

      Followed by 115 lines of this:

       

      2013-03-22 14:57:45,600 DEBUG ConfigureListener.contextInitialized(/my-service-1.0-SNAPSHOT) at ?.?(?:?)
      

       

      After which my IDE (IntelliJ 12) hangs and it and the server (JBoss 7.0.1) takes turns att using the CPU 100%.

       

      Does anyone have any idea of what is happening?