This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Best practice: logging in 3 tier web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Best practice: logging in 3 tier web application" Watch "Best practice: logging in 3 tier web application" New topic

Best practice: logging in 3 tier web application

Sachin Jai

Joined: May 05, 2005
Posts: 7
We have a web application presentation layer is done using JSF which talks to business logic layer interfaces ( supplied as jar to JSF application) and business logic access DAO layer jar file to talk to backend.

My question is: Which is the best place ( in which layer) to put "log" statement when handling the exception? Should exception be logged when first caught? or let it propagate to UI layer and there it is logged?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Good question, and you will find many answers to it. And I wouldn't necessariy argue with any of them. They each have their pros and cons.

The design I like best is using AOP. With AOP I can create a single class that is the ExceptionHandler, and in one method that is a AfterThrows advice, catch the different Exceptions, wrap them into a single ApplicationException, and log the Exception to the logger.

What this means is that there is only one single source for Exception Handling. The client only ever needs to catch one Exception, so making a nice User friendly screen that handles that one exception is easier.

It will make you only need to put try catch code in your business code when you can actually handle that exception at that point in the code. It will also remove any logging code you would have had in your business code, keeping it clean.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Best practice: logging in 3 tier web application
Similar Threads
Question from 406 test
Get connection from app/web server connection pool in backend
Error handling in web application (servlet/plsql)
Chain exceptions
Struts and JSF. What to choose to integrate with Spring and Hibernate