ErrorStackTraceLoggingAspect.aj

package aspects; 
 
import java.io.ByteArrayOutputStream; 
import java.io.PrintStream; 
import java.io.StringWriter; 
 
import ro.utcn.dsrl.utils.logging.GlobalLoopLogger; 
 
 
public aspect ErrorStackTraceLoggingAspect { 
 
     //insert pointcut for all the public methods 
     pointcut publicCall(): execution( * *(..)); 
 
     //define what to do after a method has thrown an exception 
     after() throwing (Throwable e): publicCall() { 
          ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
          PrintStream p = new PrintStream(baos); 
 
          //used the Logger configured with Log4J to output the error 
          GlobalLoopLogger.getLogger().error(baos.toString()); 
     } 
}