Hi,
You can use Spring's AOP to write a generic around advice and log method signatures, parameters and return values.
I tried following as examples:
Code:
LoggingAspect is simple POJO aspect.
public class LoggingAspect {
Logger logger = Logger.getLogger(LoggingAspect.class);
public Object log(ProceedingJoinPoint pjp) throws Throwable {
//Log method name, input
Signature sig = pjp.getSignature();
String sigName = sig.getDeclaringTypeName() + "." + sig.getName();
String arguments = "(";
Object[] args = pjp.getArgs();
if (args != null) {
for (int i = 0; i< args.length ; i++) {
arguments += args[i] + ",";
}
}
arguments += ")";
System.out.println(sigName + arguments);
Object ret = pjp.proceed();
System.out.println("Returned:[" + (ret) + "]");
return ret;
}
}
Code:
<aop:config>
<aop:pointcut id="loggerMethods"
expression="execution(* com.examples..*.*(..))"/>
<aop:aspect id="logger" ref="loggerAspect">
<aop:around pointcut-ref="loggerMethods" method="log"/>
</aop:aspect>
</aop:config>
<bean id="loggerAspect" class="com.examples.aop.logging.LoggingAspect" />
Above aspect is logging method signature with parameters and return values for all methods in "com.examples" package classes and sub packages.
Regards
Chetan