Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Logging constructor calls and exceptions

Hi,

i hope you can help me improving my aspect so that it logs constructor calls and exceptions too. What i already have is:

public aspect LogAspect {

       private static Logger communicationLogger = Logger
                       .getLogger("communicationLogger");

       private static Logger catchAllLogger = Logger.getRootLogger();

       static {
               PropertyConfigurator.configure("Logger.properties");
       }

       before(): execution(public * communication..*(..)){
               if (communicationLogger.isDebugEnabled()) {
                       communicationLogger.debug("-> "
+ thisJoinPoint.getSignature().toString()
                                       + createArgs(thisJoinPoint) + " at "
+ thisJoinPoint.getSourceLocation());
               }
       }
before(): execution(public * *..*(..)){
               if (catchAllLogger.isDebugEnabled()) {
                       catchAllLogger.debug("-> "
+ thisJoinPoint.getSignature().toString()
                                       + createArgs(thisJoinPoint) + " at "
+ thisJoinPoint.getSourceLocation());
               }
       }

after() returning(Object o): execution(public * communication..*(..)){
               if (communicationLogger.isDebugEnabled())
                       communicationLogger.debug("<- "
+ thisJoinPoint.getSignature().toString() + " at " + thisJoinPoint.getSourceLocation() + " returning: " + o);
       }

       after() returning(Object o): execution(public * *..*(..)){
               if (catchAllLogger.isDebugEnabled())
                       catchAllLogger.debug("<- "
+ thisJoinPoint.getSignature().toString() + " at " + thisJoinPoint.getSourceLocation() + " returning: " + o);
       }

       private String createArgs(JoinPoint jp) {
               StringBuffer args = new StringBuffer();
               args.append("(");
               for (int i = 0; i < jp.getArgs().length; i++) {
                       if (i > 0)
                               args.append(",");
                       args.append(jp.getArgs()[i].toString());
               }
               args.append(")");

               return args.toString();
       }

}

This logs my method calls and works fine. Now i want to log constuctor calls and exceptions too. If i use

after() throwing (Exception e): execution(public * *..*(..)){
               if (catchAllLogger.isDebugEnabled()) {
                       catchAllLogger.debug("Error "
+ thisJoinPoint.getSignature().toString()
                                       + createArgs(thisJoinPoint) + " at "
+ thisJoinPoint.getSourceLocation());
               }
       }

for logging exceptions it is never applied. And if i use

before(): execution(public new(..)){
               if (catchAllLogger.isDebugEnabled()) {
                       catchAllLogger.debug("-> "
+ thisJoinPoint.getSignature().toString()
                                       + createArgs(thisJoinPoint) + " at "
+ thisJoinPoint.getSourceLocation());
               }
       }
for logging constructor calls i get an NoAspectBoundException.

Could you help me with that?

Best regards

Murphy


Back to the top