0 Replies Latest reply on May 29, 2013 8:18 AM by erasmo2 marciano2

    How to make a web-app with logging and how to configure JBossAs7 core/Logging step by step

    erasmo2 marciano2 Master

      This guide helps you to configure logging in JBoss 7, and to configure your web-app step by step



      You have to  make a web-app and to use the following library commons-logging-1.1.3.


      Step 1

      We build together a servlet




      package it.deinformatica.marciano.logtest;


      import java.io.IOException;

      import java.io.PrintWriter;


      import javax.servlet.ServletException;

      import javax.servlet.http.HttpServlet;

      import javax.servlet.http.HttpServletRequest;

      import javax.servlet.http.HttpServletResponse;


      import org.apache.commons.logging.Log;

      import org.apache.commons.logging.LogFactory;



      * Servlet implementation class LogTester


      public class GuideLogTester extends HttpServlet {

          private static final long serialVersionUID = 1L;

          private static final Log log = LogFactory.getLog(GuideLogTester.class);



           * Default constructor.


          public GuideLogTester() {

              // TODO Auto-generated constructor stub




           * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse

           *      response)


          protected void doGet(HttpServletRequest request,

                  HttpServletResponse response) throws ServletException, IOException {

              PrintWriter out = response.getWriter();

              out.write("<h1>LogTester Application Version Guide Erasmo Marciano 1.0</h1>");

              out.write("<p>Loading this page generates multiple log events for the it.deinformatica.marciano.logtest category.</p>");

              out.write("<p>Click on F5 reload this web-page.</p>");

              out.write("<p>You wii find level log:debug|fatal|error|trace|info|warn</p>");


              for (int i = 1; i <= 20; i++) {

                  log.debug("This is DEBUG message. Event number " + i);

                  log.fatal("This is FATAL message. Event number " + i);

                  log.info("This is INFO message. Event number " + i);

                  log.error("This is ERROR message. Event number " + i);

                  log.trace("This is TRACE message. Event number " + i);

                  log.warn("This is WARN message. Event number " + i);





           * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse

           *      response)


          protected void doPost(HttpServletRequest request,

                  HttpServletResponse response) throws ServletException, IOException {

              // TODO Auto-generated method stub







      Head UP!!


      Into your web-app  don't import the  library  commons-logging-1.1.3.jar because it has been defined as extension in stadalone.xml| domain.xml


      Check into your file satndole.xml| domain.xml  <extension module="org.jboss.as.logging"/>



      Step 2


      You have to define the Logging/Handler



      You can create the new Handler with Web Interface


      Click on Profile (top-rigth)

      Click on Core/Logging (columun-left)

      Click on  Handler (NavBar Top)



      Step 3


      You have to define the Log Categories



      You can create the new Log Categories with Web Interface


      Click on  Log Categories (NavBar Top)


      Click on add


      Select your new   Log Categorie and add your Handler(Step2)





      Heap UP!!!


      Now you deploy your web-app and open a Web Broswer and point it


      You should see in console:


      12:46:10,391 ERROR [it.deinformatica.marciano.logtest.GuideLogTester] (http-/ This is FATAL message. Event number 19

      12:46:10,391 ERROR [it.deinformatica.marciano.logtest.GuideLogTester] (http-/ This is ERROR message. Event number 19






      You should have into standalone.xml these new tags



              <subsystem xmlns="urn:jboss:domain:logging:1.1">


               <console-handler name="GuideStudyLogging" autoflush="false">

                      <level name="ERROR"/>



                                  <!-- Your packege -->

                 <logger category="it.deinformatica.marciano.logtest" use-parent-handlers="true">

                      <level name="ERROR"/>


                          <handler name="GuideStudyLogging"/>