Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best practice: logging in 3 tier web application

 
Sachin Jai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic