gallery-image

we are here

3938 Somerset Circle Rochester Hills MI 48309

In Mule 4, logging is typically handled using the logger component. You can use this component to log messages at different levels such as INFO, DEBUG, WARN, and ERROR and we can use JSON logger which is one of the feature in Mule 4 that allows you to log messages in JSON format. It provides a structured and easily parsable way of logging information, which can be particularly useful for applications that require log aggregation, analysis, and monitoring using tools that support JSON formatting, logs message content and enables masking for particular fields we define.

In addition to the log message content, you can include custom attributes such as timestamp, log level, thread name, and category in the JSON log message. This provides additional context for log analysis and debugging.

Using a JSON logger instead of a standard logger offers several advantages, especially in modern software development environments where structured logging and log aggregation are crucial for effective monitoring, troubleshooting, and analysis. JSON logger in Mule 4 enhances logging capabilities by providing a structured and standardized format for log messages, facilitating easier analysis, monitoring, and troubleshooting of Mule applications.

We can’t able to find JSON logger in Exchange, We need to push the JSON logger to Exchange.

1.clone the repo

https://github.com/mulesoft-consulting/json-logger

2.Configure your Anypoint platform credentials in Settings.xml – JSON logger(cloned repo)

json-logger>template-files>settings.xml

JSON logger in Mule 4
  • ANYPOINT_USERNAME and ANYPOINT_PASSWORD are the credentials you normally use to login into our Anypoint Platform.
  • CUSTOMER_EE_REPO_USERNAME and CUSTOMER_EE_REPO_PASSWORD are the credentials provided by Mulesoft Support for customers to access our private Nexus repositories

3. Configure Anypoint platform credentials in settings.xml – Users>{username}> .m2 > settings.xml

Note: If you can’t able to find settings.xml in .m2 repo, you can copy and paste the settings.xml from the JSON logger which described in step2 inside .m2 folder.

Configure Anypoint platform credentials

4. Configure organization ID in pox.xml

We can get Org ID from our organization in anypoint platform.

Go to Access management> Business Group and retrive Org ID from Business group info

Configure organization ID in pox

Configure ORG_ID_TOKEN and ${project.groupId} with Org ID

Configure organization ID in pox

ORG_ID_TOKEN

ORG_ID_TOKEN
ORG_ID_TOKEN

${project.groupId}

5. Use the command mvn clean deploy command in command prompt to push the JSON logger to Exchange in json-logger>json-logger and Run it

mvn clean deploy
mvn clean deploy

The deployment gets successful. Now we can find that JSON logger is pushed to Exchange.

JSON logger

JSON logger

Go to Anypoint Studio> Search In Exchange > JSON logger

JSON logger
JSON loggers

Sample project for JSON logger:

Sample project for JSON logger

Scenerio 1:

Scenerio 1

Module Configuration of JSON logger:

Module Configuration of JSON logger

Application name: Name of the Mule application i.e., artifact id.

Application version: Version of the Mule application.

Environment: Name of the Environment where the application is running.

Pretty print: indicate if log entries should be formatted or single line

Log location info: Indicate if location information should be logged

Disable fields: Field meant for raw data typically useful during development and test phases (e.g. payload, attributes, vars, etc.)

Content fields data masking: Indicate which fields inside the content should be masked before from logging separated by comma.

Configuration of logger properties:

Message: Message to be logged

Trace point: Current processing stage of the logs

Priority: priority of logger

Logs from start logger

Logs from start logger

We can see this log contains message, trace point, priority, time stamp, location info, content. In content we can find the password and phoneNumber are masked like wise we configure the content fields data masking in Global configuration of JSON logger.

Scenerio: 2

Logs from start logger

Message: error data

Trace point: Exception

Logs from error logger

Logs from error logger

Conclusion:

By configuring JSON logging in Mule 4, developers can create organized logs, aiding in troubleshooting and monitoring MuleSoft apps. JSON logs provide structured data for streamlined analysis and improved visibility into system operations. This logging approach enhances log management, integrating smoothly with analysis tools for better understanding and resolution of issues.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare