wood burning stoves
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
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: 17276

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 - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link: http://aspose.com/file-tools
subject: Best practice: logging in 3 tier web application
It's not a secret anymore!