Mule4: Logging and Error Handling Framework
Sample design of a logging and error handling asset.
Join the DZone community and get the full member experience.
Join For FreeIntroduction
For any application development, reusable assets are more important, which can be shared across the organization's application. Based on requirements, it can be enhanced also. Based on my experience and knowledge, I prepare Mule4 logging and error handling framework, which can be more useful and also can get an idea to enhance according to project needs.
Design Logging Framework
Logging is most important while finding production issues, analyzing bugs, change code. It's also important to know how a request is being processing and responding back to the caller. I have come across the below 7 areas where we should log information/state of a request.
- While receiving a request by an App
- While the final response providing by an App to caller
- Request received in the main flow
- Response returned from the main flow
- Before calling a system (outbound call).
- It may be another app using HTTP, sftp, another connector
- Sending message to Queue
- Storing data into Database
- After receiving a response from a system.
- Logging the formatted error details, which can give clear information about the error.
The working code can find here.
Sample Log
A screenshot of sample log details
Design Error Handling Framework
As with logging, error handling framework is also important to identify the root cause of an error. To make it easy, we need to prepare a proper error framework mechanism, which will give more information like the HTTP response code and its actual error description. Along with that, correlationId would be more important to track the issue in cloudHub/RTF.
The working code can be found here.
Sample Error Log and Response
A screenshot of the sample error log and response
Error Log
Response in Postman
How to Use the Framework
I have also developed an API that can give more insight into how to use this logging and error handling framework. Kindly visit here to find the code and Postman script to test the framework.
Opinions expressed by DZone contributors are their own.
Comments