Mulesoft JSON logger
Logging is an
important but often overlooked part of any application. It helps track
transactions, debug errors, create dashboards, and monitor different processes.
MuleSoft uses the log4j2 standard for event logging. To follow best practices,
it's important to include key elements like transaction ID, timestamp, log
level, and relevant messages for detailed information. This article introduces
an alternative logging method using a connector called JSON-Logger.
As
the name suggests, the JSON logger outputs logs in JSON format. This format is
especially useful for integration with external log analysis tools like ELK or
Splunk. It captures important information and allows for customization of
content and fields. The JSON logger also supports sending data to AMQ or JMS.
To use a JSON logger in your application, follow the steps outlined below.
JSON
Logger Module
To
begin, you need to clone the repository to your local system. Since the JSON
logger is a custom connector not provided by MuleSoft, you will need to upload
it to Anypoint Exchange for use.
- Clone JSON Logger version 2.0.1 from https://github.com/mulesoft-consulting/json-logger using Git Bash, or download the ZIP file and use it.
- Open the pom.xml file in the json-logger directory using a text editor.
- Locate the <groupId> tag and replace ORG_ID_TOKEN with your Organization ID.
- To find your Organization ID, refer to this https://help.mulesoft.com/s/article/How-to-know-my-Organization-ID-Org-ID-on-the-Anypoint-Platform
- Navigate to the template-files folder and open the settings.xml file with a text editor.
- In the <servers> section, replace the anypoint-exchange-v3 information with your Anypoint Platform login credentials
- After entering your credentials, navigate to the cloned directory and run the shell script with your Organization ID as a parameter. This script will upload your connector to the MuleSoft Anypoint Exchange. ./deploy-to-exchange.sh <org id
- The JSON Logger connector looks like below in Anypoint Exchange.
How to Use
After installation, the JSON logger will appear in the Studio Palette, just like any standard component. You can simply drag and drop it onto the canvas.
Configure JSON Logger as shown below.
In this scenario, we log the current #[payload] and utilize the START Trace Point.
Trace Points serve to organize specific 'checkpoints' in the flow execution, aiding in the creation of more advanced dashboards and reports using the gathered data.
The JSON logger already includes the following Trace Points:
- START (Default)
- BEFORE_REQUEST
- AFTER_REQUEST
- BEFORE_TRANSFORM
- AFTER_TRANSFORM
- END
- EXCEPTION
- FLOW
Comments
Post a Comment