Log4j and AOP, how to get actual class name

后端 未结 3 1083
再見小時候
再見小時候 2021-02-05 19:59

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... i

3条回答
  •  一整个雨季
    2021-02-05 20:28

    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());
    

提交回复
热议问题