-
1. Re: Entry Exit Logging
stephen Jan 3, 2009 8:10 PM (in response to nbhatia.bhatian.comcast.net)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 Jan 8, 2009 1:39 PM (in response to 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 Jan 10, 2009 10:19 PM (in response to 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