Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traditional logging vs AOP logging

Tags:

logging

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("...");
}

or

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

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

like image 872
non sequitor Avatar asked Oct 12 '09 17:10

non sequitor


People also ask

What is AOP logging?

"Aspect-oriented Programming (AOP) complements Object-oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect." An aspect can be for example logging, transaction, etc.

Is log4j AOP?

log4j is the underlying physical logging framework. AOP allows you to intercept Class/Method calls and log accordingly either using log4j, or a facade pattern such as commons logging or (recommended) slf4j.


1 Answers

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.

like image 52
daxsorbito Avatar answered Sep 22 '22 10:09

daxsorbito