• 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

Comparison of Log4j and AspectJ for logging

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been using log4j in applications for logging messages (method entry/exits and also important information).
But currently i have to develop some common classes for logging that can be used for consistent logging across all components that are part of the project.

The main problem that is faced with log4j is that duplication of log statements in code and due to negligence on part of developers they simply avoid writing log statements.

I was analysing AspectJ for tracing and logging useful information.

Would appreciate if anyone can share any experience/suggestion for this.

Thanks
Gaurav
 
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it depends on what is the purpose of your log.

Using AOP based logging usually useful for tracing method calls, because most AOP implementations allow pre/post/around advice. Since you usually only have access to the method and its parameter/return value only..that's all the information you can log.

With standalone logging framework like log4j, it is more flexible for where/when/what to log, but it makes your code base verbose and cluttered. Let's face it, most of the time log4j is used more for runtime/production debugging support..where it print out verbose process and state information.

It goes back to what is your goal and design it appropriately.
 
Gaurav Bhatia
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the update!!

The main goals :
1. Avoid all developers from writing Log statements in their code.
2. Have enough information logged to diagnose problems in production.

Now, i think there is need to investigate how extensively i can use the pointcuts to perform logging. And in case that meets the requirements then i am sure AspectJ is all time better option.
 
Wirianto Djunaidi
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. Basically if you have your code design in good way, using most best practices in OO programming..then most of the times aspect based logging should be fine.

It's just I have seen enough enterprisey code written in procedural way where method with hundreds lines of code calling other hundreds lines of code. In that case, aspect based logging can't help too much to narrow down problem in the code because too many things going on.
 
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic