2 Replies Latest reply on Dec 15, 2006 6:38 PM by ccanning

    Using an @Logger instance outside of a SEAM POJO

    datagazetteer

      I have a feeling I'm doing something very wrong with respect to passing a reference to a log to a non-SEAM object. What happens (running under JBoss AS 4.0.5) is that the first time the non-SEAM object tries to use a log method all log output from the container stops. The application keeps running, and in fact I can remove and add the SEAM application in the deploy directory and have it redeploy but still get no logging output.

      Here is fragments of the code from the SEAM app. First, the SEAM-enabled session bean.

      @Stateful
      @Name("search")
      @Scope(ScopeType.SESSION)
      public class SearchAction implements Search {
      
       @Logger
       private Log log;
      
       @In
       ParamStore paramStore;
      
       public String search() throws Exception {
       paramStore.setLog(log);
       log.info("search.search() action called with: #0", q);
       SearchSvc searchSvc = new searchSvc();
       List<String> matchingIds = searchSvc.search(paramStore, q);
      


      Next, 'ParamStore' which holds the 'log' value. This is not an SEAM entity bean (e.g., it does not have the @Entity annotation), just a normal JavaBean.

      public class ParamStore {
      
       private Log log;
      
       public ParamStor() { }
      
       public Log getLog() {
       return log;
       }
      
       public void setLog(Log log) {
       this.log = log;
       }
      }
      


      And finally a non-SEAM object that tries to make use of it.

      public class SearchSvc {
      
       public List<String> search(ParamStore paramStore, String query)
       throws Exception {
      
       Log log=paramStore.getLog();
       log.warn("This'll never be seen. #0", "And subsequent log messages are not seen.");
       }
      }
      



        • 1. Re: Using an @Logger instance outside of a SEAM POJO
          datagazetteer

           

          "DataGazetteer" wrote:
          I have a feeling I'm doing something very wrong with respect to passing a reference to a log to a non-SEAM object. What happens (running under JBoss AS 4.0.5) is that the first time the non-SEAM object tries to use a log method all log output from the container stops. The application keeps running, and in fact I can remove and add the SEAM application in the deploy directory and have it redeploy but still get no logging output.


          Nevermind -- it had nothing to do with SEAM after all. I was making a method call into a JAR file that was stomping on the logger's configuration. After fixing that the symptoms went away. Sorry for the bother...

          • 2. Re: Using an @Logger instance outside of a SEAM POJO
            ccanning

            This is how I get/create a seam logger outside of seam managed components.

            
            import org.jboss.seam.log.Log;
            import org.jboss.seam.log.LogImpl;
            
            /**
             * This will provide various utility/helper methods for dealing with seam.
             * @author Charles Canning
             */
            public class SeamHelper {
             private SeamHelper() {
             }
            
             public static Log getLogger(Class clazz) {
             return new LogImpl(clazz);
             }
            
             public static Log getLogger(String name) {
             return new LogImpl(name);
             }
            }