10 Replies Latest reply on May 29, 2013 10:35 AM by erasmomarciano

    Problem with log4j + Jboss AS 7.1.1

    quirozariel21

      PD: Sorry for my english, I don´t Know English XD

       

      Hi.. all

       

      I have an web application with Jboss 7.1.1 + JSF 2.0 + Richfaces + Hibernate . Y want use log4j for show my logs.

      My problem is wich no show me the messagges DEBUG however show me the messagges INFO.

      Please Please help us in resolving this log4j + Jboss AS 7.1.1

       

      So ready configure mi log4j.properties.xml:

       

      log4j.rootLogger=DEBUG, stdout

       

      ### direct log messages to stdout ###

      log4j.appender.stdout=org.apache.log4j.ConsoleAppender

      log4j.appender.stdout.Target=System.out

      log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

      log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

       

      my jboss-deployment-structure.xml:

       

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

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">

          <deployment>

              <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->

              <sub-deployment name="your-subdeployment.jar">

          <exclusions>

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

              <module name="org.slf4j" />

              <module name="org.apache.commons.logging"/>

              <module name="org.log4j"/> 

              <module name="org.jboss.logging"/>

          </exclusions>

      </sub-deployment>

             

              <exclusions>

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

              </exclusions>

          </deployment>

      </jboss-deployment-structure>

       

      my  servlet:

      import java.io.File;

       

      import javax.servlet.ServletConfig;

      import javax.servlet.ServletContext;

      import javax.servlet.ServletException;

      import javax.servlet.http.HttpServlet;

       

      import org.apache.log4j.BasicConfigurator;

      import org.apache.log4j.PropertyConfigurator;

       

      public class Log4JInitServlet extends HttpServlet{

       

          /**

           *

           */

          private static final long serialVersionUID = -3677208571865966932L;

       

       

          @Override

          public void init(ServletConfig config) throws ServletException {

             System.out.println("Initialising log4j");

             String log4jLocation = config.getInitParameter("log4j-properties-location");

          

             ServletContext sc = config.getServletContext();

          

             if (log4jLocation == null) {

                System.out.println("No log4j properites...");

                BasicConfigurator.configure();

             } else {

                String webAppPath = sc.getRealPath("/");

                String log4jProp = webAppPath + log4jLocation;

                File output = new File(log4jProp);

          

                if (output.exists()) {

                   System.out.println("Initialising log4j with: " + log4jProp);

                   PropertyConfigurator.configure(log4jProp);

                } else {

                   System.out.println("Find not found (" + log4jProp + ").");

                   BasicConfigurator.configure();

                }

             }

          

             super.init(config);

          }

         

      }

       

      and this is configure in my web.xml

        <servlet>

              <servlet-name>Log4jInitservlet</servlet-name>

              <servlet-class>com.comibolcore.util.Log4jInitservlet</servlet-class>

              <init-param>

                  <param-name>log4j-properties-location</param-name>

                  <param-value>/WEB-INF/log4j.properties</param-value>

              </init-param>       

              <load-on-startup>1</load-on-startup>

          </servlet>