2 Replies Latest reply on Mar 22, 2012 4:23 PM by Martin Dames

    How to log with Weld and AS 7.1

    Martin Dames Newbie

      Hi there,

       

      Im wondering how I can use logging in my JEE6 WebApp with JBoss AS 7.1.1.

      As I know I should use slf4j, which belongs to AS 7. Then I can @Inject the appropriate Logger instance in my beans as describes in

      http://docs.jboss.org/weld/reference/1.0.1-Final/en-US/html/extensions.html

       

      But this does not work. I have added to my pom.xml:


      {code:xml}

              <artifactId>maven-war-plugin</artifactId>
              <version>2.1.1</version>
              <configuration>
                 <!-- Java EE 6 doesn't require web.xml, Maven needs to catch
                    up! -->
                 <failOnMissingWebXml>false</failOnMissingWebXml>
      <archive>
      <manifestEntries>
      <Dependencies>org.slf4j</Dependencies>
      </manifestEntries>
      </archive>
              </configuration>

      {code}

       

      Then I do not have slf4j jar in my eclipse project build path. So I can not use it. If I add a normal dependecy to slf4j in my pom.xml, then the application

      does not start anymore and JBoss Tools are saying "No bean is eligible for injection to the injection point [JSR-299 §5.2.1]".

       

      Well.... I am pretty confused about logging in JEE apps... I just want to inject a logging instance, log with debug and info, use templates... everything like Seam2 logging does...

       

      How is this possible?

       

      Thank you.

        • 1. Re: How to log with Weld and AS 7.1
          James Perkins Master

          Do you also have the dependency set in the dependency section of your POM? You might want to try that out just to see if the error goes away.

          • 2. Re: How to log with Weld and AS 7.1
            Martin Dames Newbie

            Thank you for your answer, but I found JBoss Soldier (from Seam 3) and its offers everything I need.

             

            Here are some tips:

            1. Add dependency to pom for maven (see http://seamframework.org/Seam3/Solder)

            2. Configure logging standalone.xml

            2a. add your own logger category

             

            {code:xml}

            <logger category="de.mdames">

                 <level name="TRACE"/>

            </logger>

            {code}

             

            2b. set console (or file-) handler level to TRACE

            2c. keep root logger level at INFO, otherwise JBoss AS will log too much

             

            3. Inject Logger

            {code:java}

            import org.jboss.solder.logging.Logger;

            ..

            @Inject private Logger log;

            {code}

             

            4. Use logger instance

            {code:java}

            log.debugv("Trying to authenticate {0}", username);

            {code}

             

            5. Restart JBoss AS

             

            Hope someone find this useful.