传统日志 vs AOP 日志 [英] Traditional logging vs AOP logging

查看:30
本文介绍了传统日志 vs AOP 日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始这个新项目,我们正在研究我们的日志记录/调试方法,我想把这个问题交给你们其他人,鉴于

I'm starting this new project and we are thrashing out our logging/debugging approach and I wanted to put the question to the rest of you on SO, given

private final static Logger logger = LoggerFactory.getLogger(getClass());
...
public void doSumething(){
...
if(logger.isDebugEnabled())
    logger.debug("...");
}

 @After("execution(* *.doSomething())")
    public void logAfter(JoinPoint jp){
        logger.debug("...");
    }

AOP 方法真的比使用传统方法更好吗?或者 AOP 在日志记录/分析的特定用例中表现出色?

Is the AOP approach really any better than using the traditional approach? Or does AOP excel in a particular use case for logging/profiling?

推荐答案

在性能方面,AOP 方法肯定比传统方法有一点开销.

For performance, AOP approach certainly has a little overhead against the traditional one.

AOP 的众多优势之一是它允许您将非业务关注点与业务逻辑分开.它还可以帮助您处理日常任务,例如在每个方法中放置日志记录逻辑或在每个方法上放置 try-catch 语句.

One of the many strengths of AOP is that it allows you to separate your non-business concerns from your business logic. It also helps you in mundane tasks such putting a logging logic in each of your method or place a try-catch statement on each method.

我认为真正的问题是,如果性能开销(根据我的经验,这只是最小的)能够补偿您在开发过程中必须完成的平凡任务.

I think the real issue is that if the performance overhead (in my experience which is only minimal) would compensate on the mundane tasks that you have to go through while developing.

一个朋友之前告诉我,拥有一个可维护和可扩展的速度较慢的应用程序比拥有一个会让你在维护方面陷入困境的更快的应用程序更好.缓慢可以通过多种方式进行补偿,例如升级硬件等.

A friend told me before that it's better to have a slower app that is maintainable and scalable than having a faster app that would give you hell in maintenance. Slowness could be compensated in many ways, such as upgrading hardware and etc.

这只是我的两分钱,希望对您有所帮助.

This is just my two cents, hope this helps.

这篇关于传统日志 vs AOP 日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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