Traditional logging vs AOP logging

前端 未结 4 1308
离开以前
离开以前 2020-12-01 14:40

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

priva         


        
相关标签:
4条回答
  • 2020-12-01 15:02

    I agree with @daxsorbito answer - and wanted to build on top of that.

    • The cross cutting advice can be configured using config files that way you can have a different aop advice for production logging. This may improve performance.

    • AOP Can reduce a lot of code clutter and encourage developers to focus on main task.

    • A lot of debugging becomes easier if the code has sufficient logging. AOP makes it independent of a developer. Some developer may not follow a discipline of logging enough. Or may feel it unnecessary.

    • Log file has consistent messages. (no more "you say potato, I say batata... :) " ) - Each developer may log it different style. However if we AOP-fy it you can make it consistent across application and put a lot of good analytic on top of it easily.

    • This also encourages you to write small reusable (and even better if those are sometimes testable) methods that can be easily debugged.

    • Sometimes, This will also encourage you to follow consistent naming conventions since it will make it easier to apply advices for logging those methods during debugging.

    0 讨论(0)
  • 2020-12-01 15:11

    I dont think these should be viewed as mutually exclusive alternatives.

    I think AOP is great for tracing (i.e. logging method entry/exit and parameter values).

    I still use regular logging as well:

    1. For Info/Warning/Error Messages
    2. For debug messages during development to see the value of certain variables or to see which if/then path is used etc.
    0 讨论(0)
  • 2020-12-01 15:16

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

    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.

    0 讨论(0)
  • 2020-12-01 15:16

    I'm quite found of the aspect oriented approach. It feels right to separate logging from logic. I'm not sure of the performance overhead though.

    Even if you decide not to go with AOP there are better ways of doing logging than this:

    if(logger.isDebugEnabled())

    Have a look at log4j which will enable you to change log levels, different appenders and a whole lot of other things.

    0 讨论(0)
提交回复
热议问题