I'm implementing a logger as an aspect using Spring AOP and Log4J, but I've noticed that the class name in log file is always the LoggerAspect
class name, so... is there a way to trace the actual class name in my log?
The ProceedingJoinPoint. getSignature() method returns everything you need to get the actual class name, method name, return type and parameters for the joinpoint.
log4j is the underlying physical logging framework. AOP allows you to intercept Class/Method calls and log accordingly either using log4j, or a facade pattern such as commons logging or (recommended) slf4j. without the programmer having to do it.
ProceedingJoinPoint exposes the proceed(..) method in order to support around advice in @AJ aspects. Nested Class Summary. Nested classes/interfaces inherited from interface org.aspectj.lang.JoinPoint. JoinPoint.EnclosingStaticPart, JoinPoint.StaticPart.
AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does this by adding additional behavior to existing code without modifying the code itself. Instead, we can declare the new code and the new behaviors separately.
Use : pjp.getTarget().getClass().getCanonicalName()
Also, to add logs at class level of which method is being exexuted instead using logger of advice class, use class level logger within advice method, as below
Logger logger = Logger.getLogger(pjp.getTarget().getClass().getCanonicalName());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With