Is there an aspect already written and tested well for TRACE logging

南楼画角 提交于 2019-11-30 09:32:44

问题


I am refactoring a legacy application where the actual application is scattered in between lot of logging statements. I could immediately benefit by removing TRACE level logging (method entered/exited). However this has proven to be useful many times while debugging an app while integration testing etc. So I am wondering if there is already a working and proven (being used for a while) aspect written for this? I've gone though some online posts but they seem to simple enough (and not sure if they have ever been really used) to be used for real project.


回答1:


Checkout aspects from "AspectJ in Action" (sources can be downloaded from http://manning.com/laddad2). I have used very close variations of aspects from chapter 10 on real projects.




回答2:


You can use @Loggable annotation from jcabi-aspects, together with a built-in AspectJ aspect:

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

It logs through SLF4J, which you can redirect to your own logging facility like, say, log4j.



来源:https://stackoverflow.com/questions/4653013/is-there-an-aspect-already-written-and-tested-well-for-trace-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!