Log4j and AOP how to get the actual class name

I use logger as an aspect using Spring AOP and Log4J, but I noticed that the class name in the log file is always the name of the LoggerAspect class, so ... is there a way to keep track of the actual class name in my log?

+6
source share
3 answers
 @Around("execution(* com.mycontrollerpackage.*.*(..))") public Object aroundWebMethodE(ProceedingJoinPoint pjp) throws Throwable { String packageName = pjp.getSignature().getDeclaringTypeName(); String methodName = pjp.getSignature().getName(); long start = System.currentTimeMillis(); if(!pjp.getSignature().getName().equals("initBinder")) { logger.info("Entering method [" + packageName + "." + methodName + "]"); } Object output = pjp.proceed(); long elapsedTime = System.currentTimeMillis() - start; if(!methodName.equals("initBinder")) { logger.info("Exiting method [" + packageName + "." + methodName + "]; exec time (ms): " + elapsedTime); } return output; } 
+6
source

it is easier:

 pjp.getTarget().getClass() 
+7
source

Use : pjp.getTarget().getClass().getCanonicalName()

0
source

Source: https://habr.com/ru/post/920595/


All Articles