使用 Spring AOP 进行日志记录是个好主意吗? [英] Is using Spring AOP for logging a good idea?

查看:45
本文介绍了使用 Spring AOP 进行日志记录是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在阅读 Spring,其中一个用于使用 AOP 的示例是记录方法调用的开始和结束.

I'm reading up on Spring at the moment and one of the examples used for a use of AOP is logging the start and end of method calls.

我还了解到使用 AOP 会影响性能.

I've also read that using AOP can impact performance.

对于这种类型的日志记录,使用 Spring AOP 是一个好主意吗?我的理解是,Spring 使用动态 AOP,对于这种类型的 AOP,使用静态 AOP(如 AspectJ)会更好.

Is using Spring AOP a good idea for this type of logging? My understanding is that Spring uses Dynamic AOP would it be be better to use Static AOP (Like AspectJ) for this type of AOP.

目前我工作的公司的编码政策需要大量的日志记录,我想减少我必须编写的日志记录代码的数量并提高代码的可读性.

Curently the coding policy of the company I work for requires a ridiculous amount of logging and i want to reduce the ammount of logging code I have to write and improve the readability of my code.

我是不是找错了树?

推荐答案

阅读 这篇博文关于您的性能问题.

Read this blog-post about your performance concerns.

考虑 AOP 的方式是将提供的功能优势放在首位.如果自动日志记录是您的要求并且 AOP 适合它 - 那就去做吧.

The way to think of AOP is to put the provided functional benefits in the first place. If automated logging is your requirement and AOP fits it - go for it.

也就是说,如果需要细粒度的日志记录,加载时编织当然是首选.

That said, load-time weaving is, of course, preferred if fine-grained logging is required.

这篇关于使用 Spring AOP 进行日志记录是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆