4 Replies Latest reply on Aug 17, 2015 3:39 AM by gurusathish

    Own log4j.xml on a Wildfly 8.1.0.Final doesn't work

    ant.gordiichuk

      Hi guys, could you help me,

       

      We've migrated our app from Tomcat to the last Wildfly 8.1.0.Final. After migration we've met some problem with our log4j. When application is working I see only INFO level log in the console, even when DEBUG level is enabled in our own log config. Looks like Wildfly doesn't use our config and logging all through the own logging system. I've read logging documentation but it didn't help. log4j.xml in the classpath. When I open our war file, I see that log4j in the correct place, WEB-INF/classes directory.

       

      Maybe we should make additional actions to enable own logger? We don't want make our app server dependent even if this is only logs.

       

      Our log4j.xml

       

      <?xml version="1.0" encoding="UTF-8" ?>

      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

          <appender name="console" class="org.apache.log4j.ConsoleAppender">

              <param name="Target" value="System.out"/>

              <layout class="org.apache.log4j.PatternLayout">

                  <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>

              </layout>

          </appender>

          <root>

              <priority value ="ALL" />

              <appender-ref ref="console" />

          </root>

      </log4j:configuration>

       

      pom.xml

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"

          <modelVersion>4.0.0</modelVersion>

          <artifactId>test</artifactId>

          <packaging>war</packaging>

          <groupId>test</groupId>

          <version>1.0-SNAPSHOT</version>

          <name>test</name>

       

          <dependencies>

              <!-- Spring Web MVC framework -->

              <dependency>

                  <groupId>org.springframework</groupId>

                  <artifactId>spring-webmvc</artifactId>

                  <version>4.0.3.RELEASE</version>

              </dependency>

       

              <!-- Spring ORM -->

              <dependency>

                  <groupId>org.springframework</groupId>

                  <artifactId>spring-orm</artifactId>

                  <version>4.0.3.RELEASE</version>

              </dependency>

       

              <!-- JSTL -->

              <dependency>

                  <scope>provided</scope>

                  <groupId>javax.servlet</groupId>

                  <artifactId>jstl</artifactId>

                  <version>1.2</version>

              </dependency>

       

              <!-- Apache Tiles -->

              <dependency>

                  <groupId>org.apache.tiles</groupId>

                  <artifactId>tiles-extras</artifactId>

                  <version>3.0.3</version>

              </dependency>

       

              <!-- Apache Utils -->

              <dependency>

                  <groupId>commons-io</groupId>

                  <artifactId>commons-io</artifactId>

                  <version>2.4</version>

              </dependency>

       

              <!-- Servlet API -->

              <dependency>

                  <groupId>javax.servlet</groupId>

                  <artifactId>servlet-api</artifactId>

                  <version>3.0-alpha-1</version>

              </dependency>

       

              <!-- Log4j -->

              <dependency>

                  <groupId>log4j</groupId>

                  <artifactId>log4j</artifactId>

                  <version>1.2.17</version>

              </dependency>

       

          <build>

              <finalName>${project.name}</finalName>

          </build>

      </project>

       

      Log usage

       

      private static Logger log = Logger.getLogger("myLogger");

      log.debug("debug message"); // doesn't works

      log.info("info message"); // works

        • 1. Re: Own log4j.xml on a Wildfly 8.1.0.Final doesn't work
          robert.panzer

          Hi,

           

          JBoss brings its own Log4J implementation as a module.

          Modules are always loaded first, so you are probably using the log4j implementation of JBoss that does not see the log4.xml in your application.

          If you have an own impl in your application you could try to exclude the dependency on log4j by adding this jboss-deployment-structure.xml to the WEB-INF folder of your war file.

          (I assume that you are directly deploying a war file and not an ear, right?)

           

          <?xml version="1.0" encoding="UTF-8"?>

          <jboss-deployment-structure>

            <deployment>

            <exclusions>

            <module name="org.apache.log4j" />

            </exclusions>

            </deployment>

          </jboss-deployment-structure>

           

          Kind regards,

          Robert

          • 2. Re: Own log4j.xml on a Wildfly 8.1.0.Final doesn't work
            ant.gordiichuk

            I looking for decision which don't need exclude server log4j impl. I want use it with my own log config. Documentation said:

            Per-deployment Logging

            Per-deployment logging allows you to add a logging configuration file to your deployment and have the logging for that deployment configured according to the configuration file. In an EAR the configuration should be in the META-INF directory. In a WAR or JAR deployment the configuration file can be in either theMETA-INF or WEB-INF directories.

            The following configuration files are allowed:

            • logging.properties
            • jboss-logging.properties
            • log4j.properties
            • log4j.xml
            • jboss-log4j.xml

             

            According to this I should only add my own config to the specified dir, but unfortunately it doesn't work for me.

            • 3. Re: Own log4j.xml on a Wildfly 8.1.0.Final doesn't work
              ant.gordiichuk

              Maybe it will be useful somebody to know. After some investigation we find out that in case when own log4j.xml uses, Wildfly uses our own configuration as outlined in a documentation, but with some restriction. In case when we declare file appender it works fine as we expected. But in case using console appenders, our console logs writes to the file, defined for file appender, and marked as [stdout]. So you don't find any own logs in the real console even if you use console appender. Server overrides Target System.out to org.jboss.stdio.NullOutputStream.

              • 4. Re: Own log4j.xml on a Wildfly 8.1.0.Final doesn't work
                gurusathish

                Hi Anton,

                 

                I too have the same problem. I am unable to print my info message on the console in Wildfly 8.2.0 Final, even though i have added a console appender.

                Please any own helps me to over come this problem

                 

                Thank you