3 Replies Latest reply on Jan 10, 2009 10:19 PM by nbhatia.bhatian.comcast.net

    Entry Exit Logging

    nbhatia.bhatian.comcast.net

      What is the easiest way to log entry and exit of beans in a Seam application? I would also like to selectively turn this feature on and off for different application layers.


      Thanks.
      Naresh

        • 1. Re: Entry Exit Logging
          stephen

          Depends on what you mean by entry and exit.
          Maybe interceptors will suit your needs:
            http://docs.jboss.org/ejb3/app-server/tutorial/interceptor/interceptor.html

          • 2. Re: Entry Exit Logging
            nbhatia.bhatian.comcast.net

            Stephen, thanks for pointing me in the right direction.


            After further reading, I decided to implement entry/exit logging using Seam iterceptors - since I wanted to make it work across all beans, not just EJBs. The only issue I am having right now is that I cannot be selective about which methods are logged, the relevant annotations seem to work only at the class level and ALL methods are being traced. Is there a better way?


            Here's what I have so far. Below is my trace interceptor:


            public class TraceInterceptor {
                private Log log = Logging.getLog(TraceInterceptor.class);
            
                @AroundInvoke
                public Object logEntryExit(InvocationContext invocation) throws Exception {
            
                    Method method = invocation.getMethod();
                    
                    log.trace(">>> Entering method '#0' of class [#1]",
                        method.getName(), method.getDeclaringClass().getName());
            
                    Object retVal = invocation.proceed();
            
                    log.trace("<<< Exiting method '#0' of class [#1]",
                        method.getName(), method.getDeclaringClass().getName());
            
                    return retVal;
                }
            }
            



            This is how I define my annotation called TraceMethods:


            @Target(ElementType.TYPE)
            @Retention(RetentionPolicy.RUNTIME)
            @Interceptors(TraceInterceptor.class)
            public @interface TraceMethods {
            }
            



            This is how I use the annotation on a Seam bean:


            @Name("openAccountController")
            @Scope(ScopeType.CONVERSATION)
            @TraceMethods
            public class OpenAccountController implements Serializable {
            
                public void openAccount() {
                    ...
                }
            }
            

            • 3. Re: Entry Exit Logging
              nbhatia.bhatian.comcast.net

              Can someone please confirm my conclusion in the previous post that Seam interceptors do not support intercepting specific methods? The implementation I posted intercepts all methods - I could not find a way to specify which methods should be intercepted.


              Thanks.
              Naresh