传统日志记录与AOP日志记录 [英] Traditional logging vs AOP logging

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

问题描述

我正在开始这个新项目,我们正在淘汰我们的日志记录/调试方法,我想将其余的问题都放在SO上

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.

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

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