GeeCON Prague 2014*
The moose likes Aspect Oriented Programming and the fly likes Spring AOP vs Log4j for logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Aspect Oriented Programming
Bookmark "Spring AOP vs Log4j for logging" Watch "Spring AOP vs Log4j for logging" New topic
Author

Spring AOP vs Log4j for logging

Geeta Puttappanavar
Ranch Hand

Joined: Jan 18, 2012
Posts: 43
Hi,

I’m newbie to spring. I’m facing problems to understand Spring AOP module.

1. What are the advantages of Spring AOP over log4j in case of logging.
2. When to use Spring AOP & Log4j?
3. We can log the logs into separate file. Can I do the same wrt Spring? If yes provide me the example or link to log the logs into file using Spring AOP.

Thanks in advance,
Geeta

William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

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.

Using AOP, you can enforce logging, or performance testing or a wealth of other things
without the programmer having to do it.

WP
Geeta Puttappanavar
Ranch Hand

Joined: Jan 18, 2012
Posts: 43
William P O'Sullivan wrote: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.

Using AOP, you can enforce logging, or performance testing or a wealth of other things
without the programmer having to do it.

WP



Thanks you mach William. But my doubt has not been cleared. I need explanation in depth.

Thanks,
Geeta
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1650
    
    7

What is being said is AOP does not replace the logging framework. You will still use your logging framework to log to files just like you always have. What AOP brings to the table is addressing the cross cutting concerns. Say you wanted to log a message every time you entered a method. Typically you would have to write something similar to logger.debug("I am entering a method"). Using AOP this can be done without adding this line at the beginning of every method. You will need to spend some time getting familiar with AOP before this will make total sense. Unfortunately that is to broad of a subject to explain in a forum post.

Here is a blog doing something similar to what I just described.
http://thoughtforge.net/665/creating-a-logging-aspect-with-spring-aop-and-aspectj/


[How To Ask Questions][Read before you PM me]
Geeta Puttappanavar
Ranch Hand

Joined: Jan 18, 2012
Posts: 43
Bill Gorder wrote:What is being said is AOP does not replace the logging framework. You will still use your logging framework to log to files just like you always have. What AOP brings to the table is addressing the cross cutting concerns. Say you wanted to log a message every time you entered a method. Typically you would have to write something similar to logger.debug("I am entering a method"). Using AOP this can be done without adding this line at the beginning of every method. You will need to spend some time getting familiar with AOP before this will make total sense. Unfortunately that is to broad of a subject to explain in a forum post.

Here is a blog doing something similar to what I just described.
http://thoughtforge.net/665/creating-a-logging-aspect-with-spring-aop-and-aspectj/


Hooray I got it now. .

Thank you so much,
Geeta
 
GeeCON Prague 2014
 
subject: Spring AOP vs Log4j for logging