I have one large monolithic application with four layers for specific functional requirements.
UI Layer
-> Presentation Logic Layer
-> Business Logic Layer
-> Persistent Layer
One minimal working example for call flow can be like,
class ProductViewController {
func showProduct(list){
// populate list in view
}
}
class ProductPresenter {
func sanitiseProduct(list){
// apply presentation logic to list
viewController.showProduct(list)
}
}
class ProductService {
func filerProducts(list){
// apply filtering logic to list
productPresenter.sanitiseProduct(list)
}
}
class ProductDatabase {
func retrieveProducts(){
// retrieve raw product list
productService.filerProducts(getAllProduct())
}
}
Now if any exception happens in any layer of the flow (i.e. query exception in Database layer
) I have decided to log it in each layer with appropriate TAG and info and throw back to upper layers for propagating so that while debugging, each layer can filter its own logs using appropriate TAG without looking into other layers (i.e. especially when different teams are responsible for different layers
).
While reviewing, one of my colleagues commented that in my design, there will be duplication of logs for a single exception/error which might cost performance and memory. His suggestion is to apply logging in one of the layers for specific exceptions (i.e. query exception in Persistent Layer only
). However, he suggested to continue throwing the exception to upper layers.
Is my logging approach which provides better maintainability should be changed for the sake of performance and memory? What are the general suggestions to deal with this situation?