1 2 3 Previous Next 37 Replies Latest reply on Dec 6, 2012 5:39 PM by jamezp Go to original post
      • 15. Re: How to setup log4j in JBoss AS7
        davidj

        Thanks for your help!

         

        I tried using JBoss Logging on my local machine and it did work!  That's the good news.  The bad news is that I cannot get it to work on my company's DEV and TST environments.  I have double-checked the configuration many times and it is the exact same.

         

        I tried many things on my Local machine so maybe it was something else which finally got logging to work.  On DEV and TST, I following the above directions exactly. I wonder if there's a missing step?

         

        The other Software Engineers on my team do NOT like the idea of using JBoss logging because this way our code is tied to a specific App Server.  We use other App Servers (such as Glassfish) and that is why log4j is nice because it doesn't matter which App Server is used.

         

        At this point, in-order to meet the project deadline, I will probably put "System.out.println()", because we need those logging statements!

        • 16. Re: How to setup log4j in JBoss AS7
          jamezp

          One thing to double check on your file handler is the auto-flush attribute. Make sure it's set to true. Also make sure your including a log4j.jar in you deployment if you're excluding the servers log4j. I see no reason why this wouldn't work as I know several others are using log4j successfully.

           

          JBoss Logging doesn't really tie you to JBoss AS. It's just a logging facade similar to slf4j. It will work with JBoss Log Manager, log4j, J.U.L. or logback. In some ways JBoss Logging or slf4j is better IMO. Both are just facades you can use any log manager with.

           

          --

          James R. Perkins

          • 17. Re: How to setup log4j in JBoss AS7
            ybxiang.china

            James Perkins is right!

             

            1. JBoss Logging doesn't really tie you to JBoss AS. It's just a logging facade similar to slf4j.

            2. Log4j is supported by JBOSS 7.

             

            Why NOT post your configuration and codes?

            • 18. Re: How to setup log4j in JBoss AS7
              davidj

              Hi (I'm back from Thanksgiving Vacation),

               

              Logging still does not work, but I am posting my exact configuration and code using color to highlight my relavent lines:

               

              standalone.xml:

               

              <server xmlns="urn:jboss:domain:1.2">

               

                  <extensions>

                      <extension module="org.jboss.as.clustering.infinispan"/>

                      <extension module="org.jboss.as.configadmin"/>

                      <extension module="org.jboss.as.connector"/>

                      <extension module="org.jboss.as.deployment-scanner"/>

                      <extension module="org.jboss.as.ee"/>

                      <extension module="org.jboss.as.ejb3"/>

                      <extension module="org.jboss.as.jaxrs"/>

                      <extension module="org.jboss.as.jdr"/>

                      <extension module="org.jboss.as.jmx"/>

                      <extension module="org.jboss.as.jpa"/>

                      <extension module="org.jboss.as.logging"/>

                      <extension module="org.jboss.as.mail"/>

                      <extension module="org.jboss.as.naming"/>

                      <extension module="org.jboss.as.osgi"/>

                      <extension module="org.jboss.as.pojo"/>

                      <extension module="org.jboss.as.remoting"/>

                      <extension module="org.jboss.as.sar"/>

                      <extension module="org.jboss.as.security"/>

                      <extension module="org.jboss.as.threads"/>

                      <extension module="org.jboss.as.transactions"/>

                      <extension module="org.jboss.as.web"/>

                      <extension module="org.jboss.as.webservices"/>

                      <extension module="org.jboss.as.weld"/>

                  </extensions>

               

              <profile>

                      <size-rotating-file-handler name="wms-logger">

                          <formatter>

                              <pattern-formatter pattern="%d{MMM.dd hh:mm:ss} [%c{1}] %m%n"/>

                          </formatter>

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

                          <rotate-size value="9216K"/>

                          <max-backup-index value="3"/>

                      </size-rotating-file-handler>

                      <logger category="com.incomm" use-parent-handlers="false">

                          <level name="INFO"/>

                          <handlers>

                              <handler name="wms-logger"/>

                          </handlers>

                      </logger>

               

              <logger category="com.arjuna">

                  <level name="WARN"/>

              </logger>

               

              ......

               

               

              Java Code (file called "OrderFlowBean.java):

               

              import org.jboss.logging.Logger;

               

              /**

                * EJB for pick order operations.

                * @author djensen

              */

              @Stateless(mappedName = "ejb/OrderFlowBean")

              public class OrderFlowBean implements OrderFlowBeanRemote {

                  protected static final Logger log = Logger.getLogger(OrderFlowBean.class);

               

                   public List<Orders> findByOrderId(Integer orderId) {

                        try {

                                  // do stuff

                        }

                        catch(Exception e) {

                             log.info("Error finding orders");

                        }

                   }

               

              What am I missing? What am I doing wrong?

               

              Thanks,

              David

              • 19. Re: How to setup log4j in JBoss AS7
                jamezp

                Try setting the auto-flush to true. <size-rotating-file-handler name="wms-logger" auto-flush="true">

                 

                --

                James R. Perkins

                • 20. Re: How to setup log4j in JBoss AS7
                  davidj

                  I just tried and get the following message:

                   

                  10:22:31,303 ERROR [org.jboss.as.server] JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration

                      at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                      at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                      at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                      at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]

                  Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[70,13]

                  Message: JBAS014788: Unexpected attribute 'auto-flush' encountered

                   

                   

                  Any ideas?

                  • 21. Re: How to setup log4j in JBoss AS7
                    jamezp

                    Probably because I'm an idiot. It's autoflush, no dash :-)

                     

                    --

                    James R. Perkins

                    • 22. Re: How to setup log4j in JBoss AS7
                      davidj

                      I tried "autoflush" (without dash ), but logging still doesn't work.  A file called "wms-ear.log" does get created, but nothing ever gets written to it.

                       

                      I'm wondering if this has something to do with the fact my ejb JAR file is inside of an EAR file?  I can't think of any reason why, but maybe the ear file is not correctly associating the logger with an inner jar?

                       

                      Below is a picture of what I'm saying. I have a JAR file containing a file called "OrderFlowBean.java".  This jar is inside of an ear file, which is deployed on JBoss.

                       

                      jbossLog.jpg

                      • 23. Re: How to setup log4j in JBoss AS7
                        jamezp

                        What is the package of your OrderFlowBean? It should be in com.incomm or com.incomm.something. if not, then that's the issue.

                         

                        --

                        James R. Perkins

                        • 24. Re: How to setup log4j in JBoss AS7
                          davidj

                          The package of OrderFlowBean is:

                           

                          package com.incomm.wmsdomain.ejb;

                          • 25. Re: How to setup log4j in JBoss AS7
                            jamezp

                            The only other thing I can think of is if the exception in your example above isn't throwing that exception. Have you tried logging in a @PostConstruct method just to verify that it's a logging issue?

                             

                            --

                            James R. Perkins

                            • 26. Re: How to setup log4j in JBoss AS7
                              davidj

                              Yes. In-fact, the code I've shown you is stripped-down to the basics.  There are manyfiles which have logging in them. I've even debugged to make sure that a "log.info()" line is executed.

                               

                              My local box is a Windows7 machine, but the DEV/TST/UAT servers are Linux servers.  The permissions on the "<jboss>/standalone/log" directory is "-rw-r--r--",  This might explain why the "wms-ear.log" file gets created but not written to?

                               

                              ... no, I just manual did a chmod 777 wms-ear.log, then restarted but logging still doesn't work.

                              • 27. Re: How to setup log4j in JBoss AS7
                                jamezp

                                I know it's asking a lot, but could you step into the log statement and see what's happening? We mainly need to see if the logger is going through the correct handlers.

                                 

                                --

                                James R. Perkins

                                • 28. Re: How to setup log4j in JBoss AS7
                                  davidj

                                  It's no problem to step into the log statement, in-fact I just tried it, and I got as far as the following:

                                   

                                  This is in "org.jboss.logging.JBossLogManagerLogger.class"


                                  protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) {

                                      if (parameters == null) {

                                          logger.log(loggerClassName, translate(level), String.valueOf(message), thrown);

                                      } else {

                                          logger.log(loggerClassName, translate(level), String.valueOf(message), ExtLogRecord.FormatStyle.MESSAGE_FORMAT, parameters, thrown);

                                      }

                                  }

                                   

                                  The line above in red is where I get to, but when I attempt to step-in, my IDE can't find the source code.

                                  Do you know where I can download the source code?  The "logger' object from the above line (colored red) is of type: "org.jboss.logmanager.Logger"

                                  • 29. Re: How to setup log4j in JBoss AS7
                                    jamezp

                                    Yeah, that's the JBoss Log Manager source. It should be the 1.2 branch on GitHub. You can also find it on Nexus too.

                                     

                                    --

                                    James R. Perkins