0 Replies Latest reply on Oct 30, 2014 11:11 AM by xavier flamant

    use JBoss eap with log4j

    xavier flamant Newbie



      I use JBoss eap 6.2 and Eclipse Luna. I created an enterprise application project


      Here is my project


      Capture d’écran 2014-10-30 à 16.02.07.png


      Capture d’écran 2014-10-30 à 16.02.19.png


      I put the log4j log in a stateless session bean (LibrarySessionBean)


      I put log4j logs with level info in all my methods. All the logs work except the log in a @PreDestroy method, as if the log4j was unregistred before the stateless session bean is destroyed


      Here is my Bean


      package com.tutorialspoint.sessionbean.stateless;


      import java.util.ArrayList;

      import java.util.List;


      import javax.annotation.PostConstruct;

      import javax.annotation.PreDestroy;

      import javax.ejb.Local;

      import javax.ejb.LocalBean;

      import javax.ejb.Remote;

      import javax.ejb.Stateless;


      import org.apache.logging.log4j.LogManager;

      import org.apache.logging.log4j.Logger;



      * Session Bean implementation class LibrarySessionBean


      @Stateless(name = "LibrarySessionBean")




      public class LibrarySessionBean {


          private List<String> bookShelf;


          static Logger log = LogManager.getLogger(LibrarySessionBean.class.getName());



           * Default constructor.


          public LibrarySessionBean() {

              log.info("object this.toString=" + this.toString());

              log.info("constructeur LibrarySessionBean  appele");

              bookShelf = new ArrayList<String>();





          public void addBook(String bookname) {

              log.info("object this.toString=" + this.toString());

              log.info("addbook appele");






          public List<String> getBooks() {

              return bookShelf;






          public void givingEndState() {

              log.info("givingEndState object this.toString=" + this.toString());

              for (String book : bookShelf) {

                  log.info("book found =" + book);






          public void givingStartState() {

              log.info("givingStartState object this.toString=" + this.toString());







      Here is my configuration file for log4j


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

      <configuration status="TRACE">


          <Console name="Console" target="SYSTEM_OUT">

            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>



          <File name="MyFile" fileName="logs/app.log">

              <PatternLayout pattern="%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>





          <root level="debug">

            <appender-ref ref="Console" level="info"/>

             <appender-ref ref="MyFile" level="info"/>





      Do you have an idea to solve this problem ? Thank you in advance for your answers