3 Replies Latest reply on Jan 10, 2009 10:19 PM by Naresh Bhatia

    Entry Exit Logging

    Naresh Bhatia Newbie

      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.


        • 1. Re: Entry Exit Logging
          Stephen Friedrich Novice

          Depends on what you mean by entry and exit.
          Maybe interceptors will suit your needs:

          • 2. Re: Entry Exit Logging
            Naresh Bhatia Newbie

            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);
                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:

            public @interface TraceMethods {

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

            public class OpenAccountController implements Serializable {
                public void openAccount() {

            • 3. Re: Entry Exit Logging
              Naresh Bhatia Newbie

              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.