Nav

Message Logging Policy

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.

Prerequisites

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

Message

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).

Conditional

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.

Category

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.

Level

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:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:http-policy="http://www.mulesoft.org/schema/mule/http-policy"
      xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
      http://www.mulesoft.org/schema/mule/core/current/mule.xsd
      http://www.mulesoft.org/schema/mule/http-policy
      http://www.mulesoft.org/schema/mule/http-policy/current/mule-http-policy.xsd">

<http-policy:proxy name="102280-message-logging">
  <http-policy:source>
   <try>
        <try>
          <logger level="INFO" message="#[payload]"
          category="org.mule.runtime.logging.policy-102280"/>
            <error-handler>
             <on-error-continue>
                <logger level="DEBUG" message="Before calling API turned into an error"
                        category="org.mule.runtime.logging.policy-102280"/>
             </on-error-continue>
            </error-handler>
        </try>
        <http-policy:execute-next/>
          <error-handler>
            <on-error-propagate logException="false">
            </on-error-propagate>
          </error-handler>
  </try>
  </http-policy:source>
</http-policy:proxy>
</mule>

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+