3 Replies Latest reply on May 24, 2012 1:55 PM by Wolf-Dieter Fink

    Implement log4j in Jboss 6.1.0

    Chandramohan Murugananthan Newbie



      I would like to implement the logging mechanism (Log4j) in JBoss 6.1.0. in windows environment (Web and Java projects). I suppose to start with jboss-logging.xml file but not sure about the complete steps. Could any one let me know the steps to be involved in the implementation of Log4j ? I have simple web and java projects.






        • 1. Re: Implement log4j in Jboss 6.1.0
          Wolf-Dieter Fink Master

          What you mean by 'implement' logging?


          Do you want to use log4j in your application?

          With JBoss 5/6/7 I recomment to use slf4j, the use is similar to log4j but you can use different loggin implementations.


          Use in your classes:

          private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(MyClass.class);

          method() {

          LOG.info("a info");



          In that case you can use the category "x.x.MyClass" to set the logging level witin the jboss-logging.xml


          Also I would recommend to use AS7 if you start because AS6 is not longer an active development branch.

          • 2. Re: Implement log4j in Jboss 6.1.0
            Chandramohan Murugananthan Newbie



            Yes. I want to use log4j in my application. Actually we are using reporting tool which won't support the JBoss 7. That why we choose the version 6. 


            Regarding the logging implementation,


            I declare the "logger" variable in the class level.


            private static final Logger logger = org.slf4j.LoggerFactory.getLogger(ConnectionCache.class);


            and used in the class


            logger.info("SQL value >>>> " +sql );


            In the jboss-logging.xml


               <logger category="org.ezpar.fairfax">

                  <level name="INFO"/>      



            The ConnectionCache class is come under org.ezpar.fairfax package. Do you want implement in same way ?


            To avoid compilation error for org.slf4j.LoggerFactory  I added nlog4j-1.2.19.jar in classpath. Do you want to use different jar file ?


            Where log file will create? Should I need to define path somewhere in the jboss-logging.xml or default folder( \server\default\log) ? Could you please explain steps to complete the logging process ?

            • 3. Re: Implement log4j in Jboss 6.1.0
              Wolf-Dieter Fink Master

              nlog... looks like a slf4j library in mvn repo.

              If you use AS7 you should use the jboss equivalent and make sure that you mark it as 'provided' that it is not packed in your application.


              The implementation example looks good.


              You do not need any extra configuration, the default installation of JBoss will have a root-logger on level INFO.

              The log file is located in .../server/<profile>/log (AS4/5/6) or in the standalone or domain logging directories as server.log.

              You can change the log level (as you mentioned before) or specify a separate log file in the JBoss logging configuration.