6 Replies Latest reply on Jul 19, 2007 4:06 AM by dadevilzadvocate

    Problems with log4j in jboss

    dadevilzadvocate

      Please i need help because i can't anywhere else.
      Below is the log4j properties file
      # initialise root logger with level INFO and call it
      log4j.rootLogger=INFO, BLAH
      # add a Appender to the logger BLAH
      log4j.appender.BLAH=org.apache.log4j.RollingFileAppender
      # set the layout
      log4j.appender.BLAH.layout=org.apache.log4j.PatternLayout
      #log4j.appender.BLAH.layout.ConversionPattern=%p %c - %m%n
      log4j.appender.BLAH.layout.ConversionPattern=%d{dd-MMM-yyyy HH:mm:ss:SSS}: %m%n

      log4j.appender.BLAH.File=c:/testing.log

      log4j.appender.BLAH.MaxFileSize=10000KB
      # Keep one backup file
      log4j.appender.BLAH.MaxBackupIndex=10

      Below is the code in which i am using log4j logging
      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.io.PrintWriter;
      import java.io.IOException;

      import org.apache.log4j.Logger;
      import org.apache.log4j.PropertyConfigurator;

      public class rectest extends HttpServlet
      {
      private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

      public void init(ServletConfig config) throws ServletException
      {
      super.init(config);
      String prefix = "D:/jdkwork/work/App/testing";
      String file = getInitParameter("log4j-init-file");
      // if the log4j-init-file is not set, then no point in trying
      if(file != null) {
      PropertyConfigurator.configure(prefix+file);
      }
      }
      private static Logger log =Logger.getLogger(rectest.class);
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
      doPost(request,response);
      }

      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
      response.setContentType(CONTENT_TYPE);
      PrintWriter out = response.getWriter();
      out.println("");
      out.println("rectest");
      out.println("");
      log.info("this is a test");
      out.println("The servlet has received a POST. This is the reply.");
      out.println("");
      out.close();
      }
      }
      I deploy the war file in jboss4.0.5 and run it. It runs smoothly and when deploys the war file, all the info messages in the console are then logged to the log file of my application which is deployed in it. i am new to log4j and couldn't find solution for that. please help

        • 1. Re: Problems with log4j in jboss
          alesj

           

          "dadevilzadvocate" wrote:
          It runs smoothly and when deploys the war file, all the info messages in the console are then logged to the log file of my application which is deployed in it. i am new to log4j and couldn't find solution for that. please help

          See the bolds.
          What's the problem then?

          • 2. Re: Problems with log4j in jboss
            dadevilzadvocate

            All the console messages afterwards are logged to my application's log file which i don't want. they should be logged to jboss console and my application's log file should log only its own messages.

            • 3. Re: Problems with log4j in jboss
              alesj

              Normally you configure all your (log4j) logging through global [JBOSS_HOME]\server\default\conf\log4j.xml.
              Probably some weird conflict when you also configure your own logging inside your app.

              See JBoss Wiki for more info:
              - http://www.jboss.org/wiki/Wiki.jsp?page=Logging

              • 4. Re: Problems with log4j in jboss
                dadevilzadvocate

                i have pasted my properties file and have also pasted the code which is using that properties file but i am unable to locate the problem. Instead of adding this application's entry in log4j.xml there should be something that will keep the server logging away from custom application's log file.

                • 5. Re: Problems with log4j in jboss
                  jaikiran

                  How about this:

                  
                  # initialise root logger with level INFO and call it
                  log4j.rootLogger=INFO, stdout
                  
                  #set your application to use the BLAH appender
                  log4j.logger.org.myapp=INFO, BLAH
                  
                  #configure the Console appender
                  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
                  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
                  log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
                  
                  
                  # add a Appender to the logger BLAH
                  log4j.appender.BLAH=org.apache.log4j.RollingFileAppender
                  # set the layout
                  log4j.appender.BLAH.layout=org.apache.log4j.PatternLayout
                  log4j.appender.BLAH.layout.ConversionPattern=%d{dd-MMM-yyyy HH:mm:ss:SSS}: %m%n
                  log4j.appender.BLAH.File=c:/testing.log
                  
                  log4j.appender.BLAH.MaxFileSize=10000KB
                  # Keep one backup file
                  log4j.appender.BLAH.MaxBackupIndex=10


                  Note that i have used log4j.logger.org.myapp, replace org.myapp with whatever is the package hierarchy in your application.




                  • 6. Re: Problems with log4j in jboss
                    dadevilzadvocate

                    this didn't work as well. i don't know when the deploy message my application as an info message comes in the consol after that all the console info messages are logged to the log file of my application.