4 Replies Latest reply on Oct 9, 2008 11:15 AM by asiandub

    log.info

    bartdp

      Hi,


      I have a question about the logging.
      I want to know the flow of the application so I put some logger information in the code, first the class name and then the method name.


      Example:


           public void setUsername(String username) {
                log.info("...User...setUsername...");
                this.username = username;
           }
      
      


      When I run the application I get an error on this log.info, a nullpointerexception. Why?

        • 1. Re: log.info
          chawax

          How do you inject log in your component ?
          What did you write in log config file ?
          It would be nice to post the entire class, not only the line where you have the NPE ;)

          • 2. Re: log.info
            asiandub

            why? because the variable log is null...


            a rough guess: the logger has not been injected by Seam.
            - do you use the logger in the constructor? this is called before @In is executed


            you call always fall back to conventional logging



            private static final Logger LOGGER = Logger.getLogger(MyClass.class);
            



            btw:
            class and method-name are in the standard logging output of the appender, no need to log that...


            hope that helps,
            pls post more code otherwise,


            cheers,
            Jan

            • 3. Re: log.info
              bartdp

              Ok, more information sounds logical.


              I used the annotation @Logger in my class, so the code is:


              @Entity
              @Table(name = "users")
              public class User implements Serializable {
                   @Logger
                   private Log log;
              
                   private static final long serialVersionUID = 1L;
              
                   private int id;
                   private String username;
              
                   @Column(name = "userid")
                   public int getId() {
                        log.info("...User...getId...");
                        return id;
                   }
              
                   public void setId(int id) {
                        log.info("...User...setId...");
                        this.id = id;
                   }
              
                   @Column(name = "username")
                   public String getUsername() {
                        log.info("...User...getUsername...");
                        return username;
                   }
              
                   public void setUsername(String username) {
                        log.info("...User...setUsername...");
                        this.username = username;
                   }
              


              And regarding the book, Seam in action, injecting a @Logger instance, seam can automatically create an instance of a logger that is configured exclusively for the component into which it is injected.

              • 4. Re: log.info
                asiandub

                code looks good :-)


                one possible explanation is that the seam interceptor is not registered at all.



                •   do you have ejb-jar.xml in the META-INF directory of your EAR-Project?





                •   do other @In-annotations of EJB-components work?




                cheers,
                jan