8 Replies Latest reply on Mar 28, 2007 11:44 AM by laksu

    @Logger does not inject

    laksu

      Hi,
      I have

       @Logger
       private Log logger;
      

      but i must be overseeing something basic so that logger is always null when it comes to logging.
      What could it be?
      I use SJSAS and Seam 1.2.0 p1

        • 1. Re: @Logger does not inject
          waynebagguley

          Are there any errors in the application server logs?

          • 2. Re: @Logger does not inject
            laksu

            Nope, nothing noteworthy, no Exceptions.
            If I remove log4j.xml I naturally get

            log4j:WARN No appenders could be found for logger (org.hibernate.ejb.Version).
            log4j:WARN Please initialize the log4j system properly.

            • 3. Re: @Logger does not inject
              gavin.king

              Do you have this annotation in a Seam component, ie. a class with an @Name?

              • 4. Re: @Logger does not inject
                kukeltje

                always null, or just in the constructor?

                • 5. Re: @Logger does not inject
                  gavin.king

                  Good point, Seam does not do any kind of injection until the object is fully constructed.

                  However, if you declare a @Logger field static, it will be init'd even in the constructor ;-)

                  • 6. Re: @Logger does not inject
                    laksu

                    Not in the constructor. Here is my class:

                    
                    package datassist.gop.action;
                    
                    import datassist.gop.domain.Istek;
                    import java.util.ArrayList;
                    import java.util.List;
                    import javax.ejb.Remove;
                    import javax.ejb.Stateful;
                    import javax.persistence.EntityManager;
                    import javax.persistence.PersistenceContext;
                    import javax.persistence.PersistenceContextType;
                    import org.jboss.seam.annotations.Create;
                    import org.jboss.seam.annotations.Destroy;
                    import org.jboss.seam.annotations.Logger;
                    import org.jboss.seam.annotations.Name;
                    import org.jboss.seam.annotations.datamodel.DataModel;
                    import org.jboss.seam.log.Log;
                    
                    @Stateful
                    @Name("istekler")
                    public class IsteklerAction implements IsteklerActionLocal {
                    
                     @PersistenceContext(type=PersistenceContextType.EXTENDED)
                     private EntityManager em;
                    
                     public IsteklerAction() {
                     }
                    
                     @Create
                     public void init(){
                     System.out.println("initing istekler. logger is "+((logger==null)?"null":"not null"));
                    // logger.debug("initing");
                     refresh();
                     }
                    
                     @DataModel
                     private List<Istek> istekList=new ArrayList<Istek>();
                    
                     public void refresh(){
                     System.out.println("refreshing istekler");
                    // logger.debug("refreshing");
                     istekList=em.createQuery("from Istek i").getResultList();
                     }
                    
                     public void logSomething(){
                     System.out.println("Trying to log something dummy and the logger is "+((logger==null)?"null":"not null"));
                    // logger.debug("Logging something dummy");
                     }
                    
                     @Logger
                     private Log logger;
                    
                     @Remove @Destroy
                     public void destroy(){}
                    }
                    
                    


                    • 7. Re: @Logger does not inject
                      gavin.king

                      And how do you create an instance of this class?

                      • 8. Re: @Logger does not inject
                        laksu

                        I have

                        <h:commandButton value="Log" action="#{istekler.logSomething}"/>
                        in my .xhtml file and click the button to invoke the logSomething method, so it is created by Seam.