4 Replies Latest reply on Nov 7, 2012 4:33 AM by sfcoy

    What is the best practice for logging in AS7/EAP6

    sboscarine

      I need to log activity in my Java EE code.  I can certainly bundle my own log4j, like I always did in the past, but I imagine there's a better way.  Assuming I'm deploying to EAP6/AS7.1:

      • Is there any built-in logger I can inject?
      • Can the end-user configure this logger via CLI or the UI rather than figure out where my log4j.xml is?
      • Where can I find info on how to use it?

       

       

      Thanks!!

        • 1. Re: What is the best practice for logging in AS7/EAP6
          nickarls

          Loggers can be initialized statically. Of course you can write a simple producer method for then based on InjectionPoint but I've never bothered.

          Check out https://docs.jboss.org/author/display/AS71/Logging+Configuration for configuration.

          • 2. Re: What is the best practice for logging in AS7/EAP6
            sboscarine

            Thanks for the response.  Are there any code samples of calling this logger programmatically?  I've been able to find lots of info on how to tweak the built-in loggers, but none on how to call it in Java.

             

            Also, is this logging supported on EAP and likely to be around in future EAP releases?

             

            My rationale is that I hope to use the JBoss logger so our customers can contact RedHat support if they wanted to tune the logs and also have a reasonable chance everything will work in EAP7, 8, etc.  I figured this would be more suitable than having them open up my war and look for a log4j.xml file like we used to do.

            • 3. Re: What is the best practice for logging in AS7/EAP6
              nickarls

                    private static final Logger log = Logger.getLogger(Login.class);

              ...

                    log.infof("Hello %s", user.getName());

               

              That's with JBoss logging. I've lost count on how many "lightweight wrappers around logging abstraction abstractions" there are out there. But on EAP, I'd suggest going with JBoss logging (surprise, surprise).

              • 4. Re: What is the best practice for logging in AS7/EAP6
                sfcoy

                I will throw my two bob's worth in too.

                 

                Like Nicklas, I like the JBoss logging API. You can also use it in conjunction with JBoss Solder Logging which adds the ability to inject loggers with very little code.

                 

                Whatever API that you choose, the key point is to ensure that the composition of the complete logging message is deferred until it's really needed. ie. You don't want to be performing string concatenation and/or invoking possibly expensive Object.toString() calls unless the log message is actually rendered.