Contact Free trial Login

Message Logging

This policy logs a custom message with the information available between policies, proxy, or backend at any point of the execution. This policy works with both log4j and log4j2.


You need to have the Anypoint Platform organization administrator role or have permission to create or manage APIs.

About Logging Policy Parameters

The Message Logging Policy consists of these configuration parameters:

Message Logging Policy UI
Parameter Description


A DataWeave expression that’s transformed into a message to be logged.

Note: If the payload is used as part of the message log, do not configure the Listener as non-repeatable (by default this setting is off).


The condition expressed as a DataWeave expression that returns true or false that needs to be satisfied to log the message. This field is optional.


The category that the log has. This parameter is optional. If no category is set, the default is the org.mule.runtime.logging.policy-<policy id> value.


Defines if the message is logged according to the configuration in your log4j2 file.

Before Calling API

Set to cause your logging policy to be applied before the API is called.

After Calling API

Set to cause your logging policy to be applied after the API is called.

About the Logging Format

A log has the following format: <date> <thread name> <level> <category>: <message>

category org.mule and message #[payload] (where payload value is "the payload") is:

2018-01-25 18:57:29,907 [WrapperListener_start_runner] INFO org.mule: the payload

About Policy Implementation

Logging a policy consists of the following sequence:

  1. A request is sent to the API.

  2. The message is logged, if the following are true:

    • The level and category of the log defined in the policy are included in the logger defined in the log4j2.xml configuration file.

    • The conditional field of the policy was not set, or was set, and the condition was satisfied.

  3. The API response is returned. Message Logging Policy does not interfere with the execution of any policy nor its flow.

  4. The message appears in the application log.

About Logging States

Before logging an API flow:

State before logging an API flow

After logging an API flow:

State after logging an API flow

Error handler after API flow:

State after the error handler executes

Logging Policy in XML

The following flow shows an example logging policy:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:xsi=""

<http-policy:proxy name="102280-message-logging">
	  <logger level="INFO" message="#[payload]"
		<logger level="DEBUG" message="Before calling API turned into an error"
	    <on-error-propagate logException="false">