【发布时间】:2019-01-20 16:10:13
【问题描述】:
我为我的所有存储库、服务和控制器构建了一个记录器类。我正在使用以下方法记录每个方法调用:
@Before("execution(* com.mdenis.tno..controller..*(..)) || " +
"execution(* com.mdenis.tno..service..*(..)) || " +
"execution(* com.mdenis.tno..repository..*(..))")
private void logMethodCallWithParameters(JoinPoint joinPoint)
{
String arguments = "";
for (Object argument : Arrays.asList(joinPoint.getArgs()))
{
arguments = arguments + argument.toString() + ", ";
}
if (arguments.contains(", "))
{
arguments = arguments.substring(0, arguments.lastIndexOf(","));
}
if (arguments.compareTo("") == 0)
{
logger.debug("Method " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()
+ " called with no argument");
}
else
{
logger.debug("Method " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()
+ " called with argument(s) " + arguments);
}
}
这很好用,但我的服务都扩展了一个包含常用方法的基础服务。因此,调用 PostServiceImpl 中的方法会导致以下日志语句:
Method com.mdenis.tno.service.impl.BaseServiceImpl.findAllPaginated returning with result Page 1 of 2 containing com.mdenis.tno.model.Post instances.
我想知道是否有办法记录扩展类名 (PostServiceImpl) 而不是超类名 (BaseServiceImpl)。
谢谢!
【问题讨论】:
标签: java spring-boot aspectj pointcut