• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring AOP vs Log4j for logging

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic