基于注解的日志实现

aop-log


随着公司业务逻辑逐渐复杂,越来越多的项目采用了前后端分离进行开发,提高了开发效率,但是无形中增加了沟通和调试成本。故开发人员在代码中采用了打印前端或者终端传递过来参数信息,这样当出现问题时能够排查和说明问题出在何处。aop-log就是出于这样一种使用场景而出现。总共两种注解形式,一种是:注解加在Controller上时,能够把所有的请求参数和返回参数日志以json的格式输出。二是:把注解添加在方法上时,那么只输出这个函数的输入参数和返回值。

使用说明

方法注解使用方式:

在controller上添加 @EnableMethodLog,在具体方法添加 @LogMethod
例如:

/**
 * 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注解使用方式

在controller上添加 @EnableControllerLog

@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"}
具体使用实例

https://github.com/strictnerd/web-mvc

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值