Nav

Logger Component

This component can help you monitor or even debug your Mule app by logging important information such as error messages, status notifications, payloads, and so on. You can add a Logger anywhere in a flow, and you can configure it to log a string that you specify, the output of a DataWeave expression you write, or any combination of strings and expressions.

Keep in mind that the Logger is one of the only components that supports mixing Strings and expressions within a value. DataWeave String interpolation or concatenation within a single expression should be used elsewhere.

The configured messages are logged to the app’s log file. In Studio, they appear in the Console. The following example displays the message in Set Payload in a browser while logging the message, as well.

logger-flow

Example: XML Configuration of the Flow

         
      
1
2
3
4
5
6
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081"/>
<flow name="logger-example-Flow">
  <http:listener config-ref="HTTP_Listener_Configuration" path="/"/>
  <set-payload value="Hello MuleSoft!"/>
  <logger message="#[payload]" level="INFO"/>
</flow>

Logger Configuration

logger

Field Value Description Example

Message

String or DataWeave expression

Specifies the Mule log message. By default, messages are logged to the application’s log file.

message="Current payload is #[payload]"

Level

Available options:

DEBUG, ERROR, INFO (Default), TRACE, WARN

Specifies the log level.

level="ERROR"

Category

String

Optional setting that specifies a category name that it adds to log4j2.xml file. For example, you might use a category to route your log messages based on your category, or you might set log levels based on category.

category="MyCustomCategory"

Examples

This Logger is set to monitor message processing status, mixing Strings and expressions:


         
      
1
<logger category="monitoring" message="Message #[payload.id] processed successfully" level="INFO"/>

This Logger set to record the processing time of a flow, using a single expression and DataWeave’s String concatenation:


         
      
1
 <logger category="performance" message="#['Message ' ++ payload.id ++ ' took ' ++ vars.processingTime ++ ' milliseconds to process']" level="INFO"/>