I am working on a web based application which has the following layers. The application conforms to MVC architecture and uses struts
1) JSP, tag handlers
2) Controller (struts)
3) Business tier
4) dB tier (JDO and/or JRF)
We are planning to use apache's Log4j for logging errors to log files. Log4j provides certain methods for logging errors depending upon the error severity. These methods are error(), warn(), debug() and fatal().
However, I intend to control the places where the errors should be logged to the log file. Only one tier should write/log to the log file. The most correct choice seems to be the business tier. The business tier is responsible for translating exceptions from the business tier into application specific exceptions and giving it to the controller layer. It also creates an error message for the user (which will be shown to the user on a error page for example).
The business tier will also log the error/exception to the log file. However, it needs to decide the severity of the error before calling the appropriate Log4j method. In order to do this, it will need some kind of a switch block.
I was wondering if there is a better way of logging errors and propagating exceptions given a multi-tiered application.
Kindly suggest an approach to effective exception and error handling (which involves logging as well).