1 22 package org.jboss.aspects.logging; 23 24 import org.apache.log4j.Logger; 25 import org.apache.log4j.spi.LoggingEvent; 26 import org.jboss.aop.util.PayloadKey; 27 28 import java.io.Serializable ; 29 import java.util.ArrayList ; 30 import java.util.Iterator ; 31 32 39 public class InvocationLogClientInterceptor 40 implements org.jboss.aop.advice.Interceptor, Serializable 41 { 42 44 private static final long serialVersionUID = 9191894622629072033L; 45 46 48 50 52 54 56 public String getName() 57 { 58 return "InvocationLogClientInterceptor"; 59 } 60 61 64 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) 65 throws Throwable 66 { 67 invocation.getMetaData().addMetaData(ThreadLocalAppender.LOG, ThreadLocalAppender.LOG, "Log", PayloadKey.AS_IS); 69 70 Object response = invocation.invokeNext(); 72 if (response != null) 73 dumpLog(invocation); 74 return response; 75 } 76 77 public void dumpLog(org.jboss.aop.joinpoint.Invocation invocation) 78 { 79 Logger root = Logger.getRootLogger(); 80 ArrayList list = (ArrayList ) invocation.getResponseAttachment(ThreadLocalAppender.LOG); 81 for (Iterator i = list.iterator(); i.hasNext();) 82 root.callAppenders((LoggingEvent) i.next()); 83 } 84 85 87 89 91 } 93 | Popular Tags |