• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Logging Implementation using Spring AOP or AspectJ

Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI ranchers,

I am currently working on a web project which uses struts for MVC, spring for IOC. We have used log4j for logging as usual.

But i want to remove that logging concern which is in each and every method, and centralize it using Aspect oriented programming.

Even based on the exception i want to log a particular level like if ValidationError log ERROR and if DBException log FATAL.

I want to incorporate AOP logging in all the business classes and database access classes. can this be achieved using AOP?

For AOP i have spring AOP and AspectJ. Please tell me the advantages over each other. so that using one of it adds some value to my application without any performance overhead.

Please share some urls...

Thanks for your time in advance.

Ranch Hand
Posts: 85
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I see two things here:

1) Can you use AOP for logging ? Well yes you can use AOP for implementing cross cutting concerns like Logging, security but under the covers you will still be using your log4j for actually adding lines to your log files.
Also, IMHO you will be better off using both log4j directly and spring AOP for logging. Just choose what you need to implement where.

2) Is Spring AOP better or AspectJ : This is a passage from Spring online documentation Documentation section 6.1.2 Hope it solves your problem.

Spring AOP capabilities and goals

Spring AOP's approach to AOP differs from that of most other AOP frameworks. The aim is not to provide the most complete AOP implementation (although Spring AOP is quite capable); it is rather to provide a close integration between AOP implementation and Spring IoC to help solve common problems in enterprise applications.

Thus, for example, the Spring Framework's AOP functionality is normally used in conjunction with the Spring IoC container. Aspects are configured using normal bean definition syntax (although this allows powerful "autoproxying" capabilities): this is a crucial difference from other AOP implementations. There are some things you cannot do easily or efficiently with Spring AOP, such as advise very fine-grained objects (such as domain objects typically): AspectJ is the best choice in such cases. However, our experience is that Spring AOP provides an excellent solution to most problems in J2EE applications that are amenable to AOP.

Spring AOP will never strive to compete with AspectJ to provide a comprehensive AOP solution. We believe that both proxy-based frameworks like Spring AOP and full-blown frameworks such as AspectJ are valuable, and that they are complementary, rather than in competition. Spring 2.0 seamlessly integrates Spring AOP and IoC with AspectJ, to enable all uses of AOP to be catered for within a consistent Spring-based application architecture. This integration does not affect the Spring AOP API or the AOP Alliance API: Spring AOP remains backward-compatible.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic