隨着公司業務邏輯逐漸複雜,愈來愈多的項目採用了先後端分離進行開發,提升了開發效率,可是無形中增長了溝通和調試成本。故開發人員在代碼中採用了打印前端或者終端傳遞過來參數信息,這樣當出現問題時可以排查和說明問題出在何處。aop-log就是出於這樣一種使用場景而出現。總共兩種註解形式,一種是:註解加在Controller上時,可以把全部的請求參數和返回參很多天志以json的格式輸出。二是:把註解添加在方法上時,那麼只輸出這個函數的輸入參數和返回值。前端
在controller上添加 @EnableMethodLog,在具體方法添加 @LogMethod 例如:git
/** * Created by clq on 2017/8/23. */ @Controller @RequestMapping("/admin/public") @EnableMethodLog public class TestController { @Autowired private TestDaoInteface testDaoInteface; @RequestMapping(value = "/test", method = RequestMethod.GET) @ResponseBody @LogMethod public Object test(SysUser string){ Object select = testDaoInteface.select(); // throw new IllegalArgumentException("參數非法 "); return select; } 日誌信息: 15:57:12.483 [2025955363@qtp-98801744-0] INFO com.log.aop.MethodAspect - {"method":"test","params":[{"account":"43523werwre","id":234}],"retValue":{"account":"admin","id":1},"time":3980}
在controller上添加 @EnableControllerLoggithub
@Controller @RequestMapping("/admin/public") @EnableControllerLog public class TestController {...... 日誌信息: 20:19:30.345 [1890318768@qtp-369351727-0] INFO com.log.aop.ControllerAspect - {"logTag":true,"method":"test","params":[{"account":"43523werwre","id":234}],"retValue":{"account":"admin","id":1},"time":5484,"url":"/clq-web-mvc/admin/public/test"}