8 Replies Latest reply on Sep 1, 2010 9:16 AM by pmuir

    Weld logger sl4j

    nimo22

      Weld uses sl4j with cal10n as logging framework. (Does Weld uses log4j?)


      Does anyone knows a good tutorial for using this logger in Weld?


      In Seam 2, I use this:




      @In Logger log;





      I cannot find it in Seam 3.


      However, in documentation chapter 4.11, it is described a bit:




      class LogFactory {
      @Produces Logger createLogger(InjectionPoint injectionPoint) {
      return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
      }
      }



      So I can use




      @Inject Logger log;




      Is it required to place the LogFactory in normal scoped bean (such as ApplicationScope)?






        • 1. Re: Weld logger sl4j
          nimo22

          Okay, found it:


          The weld-documentation chapter 19.1. Weld Logger explains that I can use the build-in-logger, which is sl4j-api.jar and sl4j-jdk14. So sl4j-log4j is not uses.



          Would it be better to use log4j in my Weld-Application by providing slf4j-log4j12-1.6.1.jar in my classpath..

          • 2. Re: Weld logger sl4j
            nimo22

            However, following the Documentation:



            @SessionScoped @Named
            public class MyBean{
            
            @Inject Logger log;
            
            @PostConstruct
            public void initialize()
            {
            log.info("@PostConstruct called");
            }
            
            ..
            }



            returns this Deployment-Exception:



            org.jboss.weld.exceptions.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies.  Injection point:  field com.MyBean.log;  Qualifiers:  [@javax.enterprise.inject.Default()]




            What is missing?

            • 3. Re: Weld logger sl4j
              asiandub

              should work ;-)


              can you confirm that


              - you are using


              import org.slf4j.Logger;
              


              - sl4j-api.jar is in your classpath?




              • 4. Re: Weld logger sl4j
                asiandub

                sometimes it's so easy to overlook the obvious - you'll need Weld-Extensions to use the logger.


                :-)

                • 5. Re: Weld logger sl4j
                  nimo22

                  I can use this:




                  ..
                  import org.slf4j.Logger;
                  import org.slf4j.LoggerFactory;
                  
                  @SessionScoped @Named
                  public class MyBean {
                  
                       final Logger log = LoggerFactory.getLogger(this.getClass());
                  
                  ..
                  
                  }



                  so sl4j-api.jar is in my classpath.


                  However, weld-extensions is not in my classpath.


                  The Documentation says:







                  Note
                  You can add Weld logging to your project by including weld-logger.jar, sl4j-api.jar and sl4j-jdk14.jar
                  to your project. Alternatively, express a dependency on the org.jboss.weld:weld-logger
                  Maven artifact.
                  If you are using Weld as your JSR-299 implementation, there's no need to include sl4j as it's
                  already included (and used internally).


                  I am using Weld as my JSR-299 implementation (included in JBOSS AS M4).



                  But it does not say anything about weld-extensions!


                  Where can I get the Weld-Extensions (via Maven)?


                  http://seamframework.org/Weld/PortableExtensionsPackage says nothing about how to get it!


                  • 6. Re: Weld logger sl4j
                    nimo22

                    Okay, found it.


                    This


                    <dependency>
                              <groupId>org.jboss.weld</groupId>
                              <artifactId>weld-extensions</artifactId>
                              <version>1.0.0.Alpha2</version>
                              <scope>import</scope>
                    </dependency>




                    includes the weld-extensions into my project.



                    Thanks Jan.



                    • 7. Re: Weld logger sl4j
                      nimo22

                      Would be nice to include this in the Weld-Documentation (at least in chapter 19).

                      • 8. Re: Weld logger sl4j
                        pmuir

                        We are in the process of rebuilding the docs for weldx :-)