1 2 Previous Next 18 Replies Latest reply on Jul 5, 2012 8:00 AM by Sam W

    Log4j not working with JBOSS 7.2

    Sam W Expert

      Hi

      With Jboss 7.2, log4j logger is not working in my configration. There is no logging message with logger.debug(...) in server.log file.

       

      Here is the relevant log4j configuration I can find in standalone.xml file:

       

       

      <subsystem xmlns="urn:jboss:domain:osgi:1.1" activation="lazy">

                  <configuration pid="org.apache.felix.webconsole.internal.servlet.OsgiManager">

                      <property name="manager.root" value="jboss-osgi"/>

                  </configuration>

                  <properties>

                      <property name="org.jboss.osgi.system.modules">

                          org.apache.commons.logging,

                          org.apache.log4j,

                          org.jboss.as.osgi,

                          org.slf4j,

                      </property>

                      <property name="org.osgi.framework.startlevel.beginning">

                          1

                      </property>

                      <property name="org.osgi.framework.system.packages.extra">

                          org.apache.commons.logging;version=1.1.1,

                           org.apache.log4j;version=1.2,

                           org.jboss.as.osgi.service;version=7.0,

                           org.jboss.osgi.deployment.interceptor;version=1.0,

                           org.jboss.osgi.spi.capability;version=1.0,

                           org.jboss.osgi.spi.util;version=1.0,

                           org.jboss.osgi.testing;version=1.0,

                           org.jboss.osgi.vfs;version=1.0,

                           org.slf4j;version=1.5.10,

                      </property>

                  </properties>

       

       

      Any suggestion is well preciated.

      Thanks

      Sam

        • 1. Re: Log4j not working with JBOSS 7.2
          Sam W Expert

          sorry it is JBOSS 7.1 rather than 7.2.

          Here is its boot.log file:

           

           

          03:12:37,939 INFO  [org.jboss.modules] JBoss Modules version 1.0.2.GA

          03:12:38,113 INFO  [org.jboss.msc] JBoss MSC version 1.0.1.GA

          03:12:38,148 INFO  [org.jboss.as] JBoss AS 7.1.0.Alpha2-SNAPSHOT "Ahoy!" starting

          03:12:38,150 DEBUG [org.jboss.as.config] Configured system properties:

                  file.encoding = ISO8859-1

                  file.encoding.pkg = sun.io

                  file.separator = /

                  java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment

                  java.awt.headless = true

                  java.awt.printerjob = sun.print.PSPrinterJob

                  java.class.path = /usr/local/users/jboss/jboss71A2/jboss-modules.jar

                  java.class.version = 50.0

                  java.endorsed.dirs = /usr/local/diablo-jdk1.6.0/jre/lib/endorsed

                  java.ext.dirs = /usr/local/diablo-jdk1.6.0/jre/lib/ext:/usr/java/packages/lib/ext

                  java.home = /usr/local/diablo-jdk1.6.0/jre

                  java.io.tmpdir = /var/tmp/

                  java.library.path = /usr/local/diablo-jdk1.6.0/jre/lib/amd64/server:/usr/local/diablo-jdk1.6.0/jre/lib/amd64:/usr/local/diablo-jdk1.6.0/jre/../lib/amd64:/usr/java/packages/lib/amd64:/l

          ib:/usr/lib:/usr/local/lib

                  java.net.preferIPv4Stack = true

                  java.runtime.name = Diablo Java(TM) SE Runtime Environment

                  java.runtime.version = 1.6.0_07-b02

                  java.specification.name = Java Platform API Specification

                  java.specification.vendor = Sun Microsystems Inc.

                  java.specification.version = 1.6

                  java.util.logging.manager = org.jboss.logmanager.LogManager

                  java.vendor = The FreeBSD Foundation

                  java.vendor.url = http://www.freebsd.org/java/

                  java.vendor.url.bug = http://www.freebsd.org/send-pr.html

                  java.version = 1.6.0_07

                  java.vm.info = mixed mode

                  java.vm.name = Diablo Java HotSpot(TM) 64-Bit Server VM

                  java.vm.specification.name = Java Virtual Machine Specification

                  java.vm.specification.vendor = Sun Microsystems Inc.

                  java.vm.specification.version = 1.0

                  java.vm.vendor = The FreeBSD Foundation

                  java.vm.version = 10.0-b23

                  javax.xml.datatype.DatatypeFactory = __redirected.__DatatypeFactory

                  javax.xml.parsers.DocumentBuilderFactory = __redirected.__DocumentBuilderFactory

                  javax.xml.parsers.SAXParserFactory = __redirected.__SAXParserFactory

                  javax.xml.stream.XMLEventFactory = __redirected.__XMLEventFactory

                  javax.xml.stream.XMLInputFactory = __redirected.__XMLInputFactory

                  javax.xml.stream.XMLOutputFactory = __redirected.__XMLOutputFactory

                  javax.xml.transform.TransformerFactory = __redirected.__TransformerFactory

                  javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema = __redirected.__SchemaFactory

                  javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom = __redirected.__XPathFactory

                  jboss.home.dir = /usr/local/users/jboss/jboss71A2

                  jboss.host.name = portal

                  jboss.modules.dir = /usr/local/users/jboss/jboss71A2/modules

                  jboss.modules.system.pkgs = org.jboss.byteman

                  jboss.node.name = portal

                  jboss.qualified.host.name = portal.ixsystems.com.au

                  jboss.server.base.dir = /usr/local/users/jboss/jboss71A2/standalone

                  jboss.server.config.dir = /usr/local/users/jboss/jboss71A2/standalone/configuration

                  jboss.server.data.dir = /usr/local/users/jboss/jboss71A2/standalone/data

                  jboss.server.deploy.dir = /usr/local/users/jboss/jboss71A2/standalone/data/content

                  jboss.server.log.dir = /usr/local/users/jboss/jboss71A2/standalone/log

           

          • 2. Re: Log4j not working with JBOSS 7.2
            nursa Newbie

            Hi Sam,

             

            I think the default logging level is "INFO", so you'll have to change the root logger, or the individual appenders, depending on your requirements.

             

            My standalone.xml looks like this:

             

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

                        <console-handler name="CONSOLE">

                            <level name="INFO"/>

                            <formatter>

                                <pattern-formatter pattern="%d{HH:mm:ss.SSS} %-5p [%c] (%t) %s%E%n"/>

                            </formatter>

                        </console-handler>

                        <periodic-rotating-file-handler name="FILE">

                            <level name="DEBUG"/>

                            <formatter>

                                <pattern-formatter pattern="%d{HH:mm:ss.SSS} %-5p [%c] (%t) %s%E%n"/>

                            </formatter>

                            <file relative-to="jboss.server.log.dir" path="server.log"/>

                            <suffix value=".yyyy-MM-dd"/>

                            <append value="true"/>

                        </periodic-rotating-file-handler>

                        <logger category="com.arjuna">

                            <level name="WARN"/>

                        </logger>

                        <logger category="org.apache.tomcat.util.modeler">

                            <level name="WARN"/>

                        </logger>

                        <logger category="sun.rmi">

                            <level name="WARN"/>

                        </logger>

                        <logger category="jacorb">

                            <level name="WARN"/>

                        </logger>

                        <logger category="jacorb.config">

                            <level name="ERROR"/>

                        </logger>

                        <root-logger>

                            <level name="INFO"/>

                            <handlers>

                                <handler name="CONSOLE"/>

                                <handler name="FILE"/>

                            </handlers>

                        </root-logger>

                    </subsystem>

             

            So the console gives:

            14:13:58.093 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "as7.test.ear"

            14:14:37.087 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) CALL: HelloWorld

            14:14:38.228 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Exiting...

            14:14:38.447 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) CALL: HelloWorld

            14:14:38.478 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Exiting...

             

            And the server.log gives:

            14:13:58.093 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "as7.test.ear"

            14:14:37.087 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) CALL: HelloWorld

            14:14:37.087 DEBUG [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Creating Sql objects...

            14:14:38.150 DEBUG [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Calling procedure...

            14:14:38.212 DEBUG [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Setting response...

            14:14:38.228 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Exiting...

            14:14:38.447 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) CALL: HelloWorld

            14:14:38.447 DEBUG [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Creating Sql objects...

            14:14:38.478 DEBUG [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Calling procedure...

            14:14:38.478 DEBUG [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Setting response...

            14:14:38.478 INFO  [ejb.PersistenceLayerBean] (http--127.0.0.1-8080-1) Exiting...

             

            Hope that helps a bit!

            • 3. Re: Log4j not working with JBOSS 7.2
              Sam W Expert

              Hi thank you for your suggession.

              I have have looked into the relevant part of my xml file, it is same as yours:

               

               

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

                          <console-handler name="CONSOLE" autoflush="true">

                              <level name="INFO"/>

                              <formatter>

                                  <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                              </formatter>

                          </console-handler>

                          <periodic-rotating-file-handler name="FILE" autoflush="true">

                              <level name="INFO"/>

                              <formatter>

                                  <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                              </formatter>

                              <file relative-to="jboss.server.log.dir" path="server.log"/>

                              <suffix value=".yyyy-MM-dd"/>

                              <append value="true"/>

                          </periodic-rotating-file-handler>

                          <logger category="com.arjuna">

                              <level name="WARN"/>

                          </logger>

                          <logger category="org.apache.tomcat.util.modeler">

                              <level name="WARN"/>

                          </logger>

                          <logger category="sun.rmi">

                              <level name="WARN"/>

                          </logger>

                          <logger category="jacorb">

                              <level name="WARN"/>

                          </logger>

                          <logger category="jacorb.config">

                              <level name="ERROR"/>

                          </logger>

                          <root-logger>

                              <level name="INFO"/>

                              <handlers>

                                  <handler name="CONSOLE"/>

                                  <handler name="FILE"/>

                              </handlers>

                          </root-logger>

                      </subsystem>

               

               

              Do you meant I need to change the level name of root-logger to DEBUG? as it is currently written as INFO.

              Thanks

              Sam

              • 4. Re: Log4j not working with JBOSS 7.2
                Sam W Expert

                I have changed the xml configuration to the following code:

                 

                <root-logger>

                                <level name="DEBUG"/>

                                <handlers>

                                    <handler name="CONSOLE"/>

                                    <handler name="FILE"/>

                                </handlers>

                            </root-logger>

                 

                I don't see my debugging message written into the server.log file.

                 

                Here is the relevant part of a java file:

                 

                 

                import org.apache.log4j.Logger;

                 

                public class CategoryImageServlet extends HttpServlet {

                 

                 

                     private static final long serialVersionUID = 1L;

                     private static final Logger logger = Logger.getLogger(CategoryImageServlet.class);

                 

                     private CategoryImageService categoryImageService = new CategoryImageServiceImpl();

                 

                     protected void doGet(HttpServletRequest request, HttpServletResponse response)

                        throws ServletException, IOException

                     {

                         // Get ID from request.

                        String categoryId = request.getParameter("id");

                        logger.debug("******CategoryImageServlet******: : "+categoryId);

                 

                Thanks

                Sam

                • 5. Re: Log4j not working with JBOSS 7.2
                  nursa Newbie

                  Hi Sam,

                   

                  The individual handlers override the root-logger level if they are less verbose, so you should put a lower level in the individual handlers or remove them alltogether:

                   

                              <console-handler name="CONSOLE">

                                  <level name="INFO"/>      (this doesn't need to be here really)

                                  <formatter>

                                      <pattern-formatter pattern="%d{HH:mm:ss.SSS} %-5p [%c] (%t) %s%E%n"/>

                                  </formatter>

                              </console-handler>

                              <periodic-rotating-file-handler name="FILE">

                                  <level name="DEBUG"/>

                                  <formatter>

                                      <pattern-formatter pattern="%d{HH:mm:ss.SSS} %-5p [%c] (%t) %s%E%n"/>

                                  </formatter>

                                  <file relative-to="jboss.server.log.dir" path="server.log"/>

                                  <suffix value=".yyyy-MM-dd"/>

                                  <append value="true"/>

                              </periodic-rotating-file-handler>

                   

                              <root-logger>

                                  <level name="INFO"/>

                                  <handlers>

                                      <handler name="CONSOLE"/>

                                      <handler name="FILE"/>

                                  </handlers>

                              </root-logger>

                   

                   

                  OR, if you want them all debug try:

                   

                              <console-handler name="CONSOLE">

                                  <formatter>

                                      <pattern-formatter pattern="%d{HH:mm:ss.SSS} %-5p [%c] (%t) %s%E%n"/>

                                  </formatter>

                              </console-handler>

                              <periodic-rotating-file-handler name="FILE">

                                  <formatter>

                                      <pattern-formatter pattern="%d{HH:mm:ss.SSS} %-5p [%c] (%t) %s%E%n"/>

                                  </formatter>

                                  <file relative-to="jboss.server.log.dir" path="server.log"/>

                                  <suffix value=".yyyy-MM-dd"/>

                                  <append value="true"/>

                              </periodic-rotating-file-handler>

                   

                              <root-logger>

                                  <level name="DEBUG"/>

                                  <handlers>

                                      <handler name="CONSOLE"/>

                                      <handler name="FILE"/>

                                  </handlers>

                              </root-logger>

                   

                  You should see a big difference in the console boot log with the second config

                  • 6. Re: Log4j not working with JBOSS 7.2
                    Sam W Expert

                    Thank you very much for showing how to show DEBUG messages in the server.log file, but my Controller can't write log4j debug message into the server.log file.

                    The following debugging messages are not shown in the log file:

                     

                     

                    import org.apache.log4j.Logger;

                     

                    @Controller

                    @RequestMapping("/category/image")

                    public class CategoryImageController {

                     

                    private static final Logger logger = Logger.getLogger(CategoryImageController.class);

                     

                    @RequestMapping(value="{processDefinitionKey}", method = RequestMethod.GET)

                    public ResponseEntity<byte[]> showImage(@PathVariable String  processDefinitionKey, Model model) throws Exception

                    {

                            String categoryId = processDefinitionKey;

                            logger.debug("=======showImage() - categoryId: "+categoryId);

                            List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Integer.parseInt(categoryId), 0, categoryImageService.count()) ;

                               if (ciList.isEmpty()) {

                                   logger.debug("========cList is Empty");

                                   return null;

                               }

                               logger.debug(" ========before ciList.get(0)");

                               CategoryImages ci = ciList.get(0);

                               int imageLength = ci.getImageData().length;

                               try {

                                    logger.debug(" =======in Try Block======= ");

                                    InputStream image = new ByteArrayInputStream(ci.getImageData());

                                    byte[] imageBytes = IOUtils.toByteArray(image);

                                    logger.debug(" =======imageBytes length: "+imageBytes.length);

                     

                     

                                    HttpHeaders headers = new HttpHeaders();

                                    headers.setContentType(MediaType.IMAGE_JPEG);

                                    headers.setContentLength(imageBytes.length);

                                    logger.debug(" =========headers: "+headers.toString());

                     

                     

                                    return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);

                                } catch (Exception e) {

                                    throw new RuntimeException(e);

                                }

                    }

                     

                    Thanks

                    Sam

                    • 7. Re: Log4j not working with JBOSS 7.2
                      Wolf-Dieter Fink Master

                      First I would recommend to use 7.1.1.Final (your first log show 7.1.0.Alpha2).

                       

                      If you use a fresh installation the logging should be working (console is restricted to INFO).

                      Maybe set your class with logging fatal/error/warn/info also to test whether the logging works in general.

                       

                      You might add

                                <logger category="....CategoryImageController">

                                      <level name="TRACE"/>

                                  </logger>

                       

                      for your class special or only your package.

                      • 8. Re: Log4j not working with JBOSS 7.2
                        Sam W Expert

                        Thanks very much for the suggestion.

                        I may indeed need to upgrade to 7.2 and then try again.

                        Thanks a lot

                        Sam

                        • 9. Re: Log4j not working with JBOSS 7.2
                          Sam W Expert

                          Can you also tell me where can I download jboss 7.2 release?

                          Thanks

                          Sam

                          • 10. Re: Log4j not working with JBOSS 7.2
                            Wolf-Dieter Fink Master

                            7.2 is not released right now, so you might use github.

                             

                            The latest download version is 7.1.1.Final here

                            • 11. Re: Log4j not working with JBOSS 7.2
                              Sam W Expert

                              I tried to build 7.1.2 Final, but failed with the following errors:

                               

                               

                              [INFO] BUILD FAILURE

                              [INFO] ------------------------------------------------------------------------

                              [INFO] Total time: 3:55.303s

                              [INFO] Finished at: Thu Jul 05 10:08:24 EST 2012

                              [INFO] Final Memory: 239M/481M

                              [INFO] ------------------------------------------------------------------------

                              [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.11:test (default-test) on project jboss-as-platform-mbean: There are test failures.

                              [ERROR]

                              [ERROR] Please refer to /usr/local/users/jboss/jboss-as/platform-mbean/target/surefire-reports for the individual test results.

                              [ERROR] -> [Help 1]

                              [ERROR]

                              [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

                              [ERROR] Re-run Maven using the -X switch to enable full debug logging.

                              [ERROR]

                              [ERROR] For more information about the errors and possible solutions, please read the following articles:

                              [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

                              [ERROR]

                              [ERROR] After correcting the problems, you can resume the build with the command

                              [ERROR]   mvn <goals> -rf :jboss-as-platform-mbean

                               

                               

                              Is there a pre-built 7.1.2.Final available for download?
                              thanks

                              Sam

                              • 12. Re: Log4j not working with JBOSS 7.2
                                Sam W Expert

                                I am not sure if the following steps I used to build 7.1.2 final is correct:

                                 

                                 

                                git clone https://github.com/jbossas/jboss-as.git

                                cd jboss-as

                                git checkout 7.1.2.Final

                                mvn clean install -Prelease

                                 

                                 

                                • 13. Re: Log4j not working with JBOSS 7.2
                                  Wolf-Dieter Fink Master

                                  use : mvn clean install

                                  after that the server is build in build/target/jboss......

                                  • 14. Re: Log4j not working with JBOSS 7.2
                                    Sam W Expert

                                    Thank you for your suggestion.

                                    I got the same error with mvn clean install.

                                    Thanks

                                    Sam

                                    1 2 Previous Next