• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring AOP vs Log4j for logging

 
Geeta Puttappanavar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Geeta Puttappanavar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic