Author: Neelam Deshmukh
1. Overview
Logging is useful for monitoring and troubleshooting your Mule applications and the Mule server — whether that’s recording errors raised by the application or specific details, such as status notifications, custom metadata, and payloads.
The out-of-the-box logger component offered by Mule runtime is really easy to use and understand, but it hardly enforces any standards and does not facilitate the creation of structured logs.
In this blog, we will learn an approach to keep the logging experience as simple as writing a one text entry, while having a full fledgeJSON structure as the output using JSON logger,its features and how to use it.
2. JSON logger module
The JSON Logger connector looks like below in Anypoint Exchange.

You can download it from exchange by using MuleSoft premium or guest account in Anypoint Studio and add it in Mule palette.

3. Feature of JSON Logger
Below are two important features of Json Logger:
- Log Location Info
Location object gives you everything you want to know about where you are in your application. This is what it looks like as below:

As you can see, critical troubleshooting information such as the name of the flow (rootContainer), name of the xml configuration file (fileName), and the exact line number where the logger is located (lineInFile) can now be part of the log metadata and configured through the global config element:

- Disabled Fields
JSON logger provides two very distinct fields out-of-the-box:
- message:Field meant for meaningful non-sensitive functional messages such as “Request received from Customer with ID: 1234”
- content:Field meant for raw data typically useful during development and test phases (e.g. payload, attributes, vars, etc.)
If somehow we are able to point our development team in the right direction and have them log valuable non-sensitive data in the messagefield, and any raw troubleshooting data into the contentfield, then we can leverage the “disabled fields” feature to filter certain log fields from being printed (e.g. content):

The above example will effectively tell the JSON logger that it needs to skip any field defined here (you can add many comma-separated fields, e.g. content, message, etc.). Taking this a step further, we could assign an environment variable (e.g. ${logger.disabled.fields}), which in lower environments could be null, but then on stage and production could be set to “content.”
4. How to Use
Below are steps for usage:
Step 1: As you can see in the image above , once installed, the JSON logger will show in the Studio Palette as any standard component; it can also be dragged-and-dropped into the canvas.

Step 2: Configure Json Logger

In this scenario, we are logging the current #[payload] and using the START Trace Point.
Trace Points aims to facilitate the standardization of certain “checkpoints” throughout the flow execution, which, in turn, enable more intelligent dashboards and reporting based on this data.
The current JSON logger ships with the following Trace Points:
- START (Default)
- BEFORE_REQUEST
- AFTER_REQUEST
- BEFORE_TRANSFORM
- AFTER_TRANSFORM
- END
- EXCEPTION
- FLOW
In the connector, you will see the following configuration by default:

- The application name is equivalent to your application name
- The application version is equivalent to your application version
- The environment is equivalent to your application environment
5. Conclusion
In this tutorial, we looked at what JSON Logger is,some of its key features and how to use it.