How can i log every method called in a class automatically with log4j

后端 未结 3 1554
粉色の甜心
粉色の甜心 2021-02-02 14:17

I have a class with database calls, and I generally want to log every method called (with arguments) in this class with log4j:

logger.debug(\"foo(id=\"+id+\") in         


        
3条回答
  •  渐次进展
    2021-02-02 14:31

    Try @Loggable annotation and an AspectJ aspect from jcabi-aspects (I'm a developer):

    @Loggable(Loggable.INFO)
    public String load(URL url) {
      return url.openConnection().getContent();
    }
    

    All method calls are logged through SLF4J.

    This blog post explains it step by step: Java Method Logging with AOP and Annotations

提交回复
热议问题