---
schema_version: "1"
id: 2d790a797e55784e29815453aacbf304e417aeae2c5ebfd343a9e5b0be2422c7
title: Outbound Message Logging Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/policies-outbound-message-logging.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/policies-outbound-message-logging
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b3fd3fa7d3397d35775ac3165eca1aef9798b2db5cfc069db35b90d6d0b13d94
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
# Outbound Message Logging Policy

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-right valign-top"><p class="tableblock"><strong>Policy name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Outbound Message Logging</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top"><p class="tableblock"><strong>Summary</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Logs custom messages from outbound requests sent to upstream services, responses from upstream services, or information from other outbound policies applied to the same upstream service</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top"><p class="tableblock"><strong>Category</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Troubleshooting</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-top"><p class="tableblock"><strong>First Flex Gateway version available</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">v1.11.0</p></td>
</tr>
<tr>
<td class="tableblock halign-right valign-middle"><p class="tableblock"><strong>Returned Status Codes</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No return codes exist for this policy</p></td>
</tr>
</tbody>
</table>

## [](#summary)Summary

The Outbound Message Logging policy logs custom messages from outbound requests sent to upstream services, responses from upstream services, or information from other outbound policies applied to the same upstream service. This policy is applied at the upstream level.

## [](#configuring-policy-parameters)Configuring Policy Parameters

### [](#local-mode)Flex Gateway Local Mode

When you apply the policy via declarative configuration files, Refer to the following policy definition and table of parameters:

apiVersion: gateway.mulesoft.com/v1beta1
kind: PolicyBinding
metadata:
  name: outbound-message-logging
spec:
  targetRef:
    kind: Service
    name: upstream
  policyRef:
    name: message-logging-outbound-flex
  config:
    loggingConfiguration: <array>
      - itemName: <string> // REQUIRED
        itemData: //REQUIRED
          message: <dataweave> // REQUIRED
          conditional: <dataweave> // OPTIONAL
          category: <string> // OPTIONAL
          level: <string> // REQUIRED
          firstSection: <bool> // OPTIONAL
          secondSection: <bool> // OPTIONAL

<table class="tableblock frame-all grid-all fit-content spread">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Required or Optional</th>
<th class="tableblock halign-left valign-top">Default Value</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Required</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>N/A</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Array of configurations.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemName</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Required</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>N/A</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Configuration name.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemData.message</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Required</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>N/A</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>DataWeave expression that resolves to the message log. To learn more about supported DataWeave expressions, see <a href="#dataweave-support">DataWeave Expressions Support</a>.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemData.conditional</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Optional</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>true</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>DataWeave expression that resolves to whether the message should be logged. To learn more about supported DataWeave expressions, see <a href="#dataweave-support">DataWeave Expressions Support</a>.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemData.category</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Optional</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Default category</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Log message prefix that indicates the package and class where the log is executed.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemData.level</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Required</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>N/A</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Defines the level of message to log: <code>INFO</code>, <code>WARN</code>, <code>ERROR</code>, or <code>DEBUG</code><br>
For more information, see <a href="#severity-levels">Message Logging Severity Levels</a>.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemData.firstSection</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Optional</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>false</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Boolean that indicates if messages are logged before the outbound request is sent to the upstream service, taking into account the order in which this policy is applied.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>loggingConfiguration.itemData.secondSection</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Optional</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>false</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Boolean that indicates if messages are logged after receiving the response from the upstream service, taking into account the order in which this policy is applied.</p>
</div></div></td>
</tr>
</tbody>
</table>

#### [](#resource-configuration-example)Resource Configuration Example

apiVersion: gateway.mulesoft.com/v1beta1
kind: PolicyBinding
metadata:
  name: outbound-message-logging
spec:
  targetRef:
    kind: Service
    name: my-upstream
  policyRef:
    name: message-logging-outbound-flex
  config:
    loggingConfiguration:
      - itemName: "Outbound Request Log"
        itemData:
          message: "#\[payload\]"
          conditional: "#\[attributes.queryParams\['debug'\]=='true'\]"
          level: "INFO"
          firstSection: true
      - itemName: "Outbound Response Log"
        itemData:
          message: "#\['Upstream response: ' ++ attributes.statusCode as String\]"
          level: "INFO"
          secondSection: true

### [](#connected-mode)Managed Flex Gateway and Flex Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

<table class="tableblock frame-all grid-all fit-content spread">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Required or Optional</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Message</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A DataWeave expression for extracting the message to be logged from outbound requests or upstream responses. To learn more about supported DataWeave expressions, see <a href="#dataweave-support">DataWeave Expressions Support</a>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Required</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Conditional</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A DataWeave Boolean expression used to specify whether a message is to be logged. To learn more about supported DataWeave expressions, see <a href="#dataweave-support">DataWeave Expressions Support</a>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Category</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A prefix in the log message that indicates the package and class where the log is executed.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Level</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The level of message to log: <code>INFO</code>, <code>WARN</code>, <code>ERROR</code>, or <code>DEBUG</code>.<br>
For more information, see <a href="#severity-levels">Message Logging Severity Levels</a>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Required</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Before Sending Request</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Set to cause your logging policy to log messages before the outbound request is sent to the upstream service, taking into account the order in which this policy is applied.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">After Receiving Response</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Set to cause your logging policy to log messages after receiving the response from the upstream service, taking into account the order in which this policy is applied.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional</p></td>
</tr>
</tbody>
</table>

## [](#dataweave-support)DataWeave Expressions Support

The Outbound Message Logging policy supports the [standard DataWeave Expressions supported by Flex Gateway policies](https://docs.mulesoft.com/gateway/1.12/policies-flex-dataweave-support) and the following additional [`vars`](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context) DataWeave expressions. Format the following expressions `[vars.<expressions>]`, for example `[vars.orgId]`:

- `orgId`
- `masterOrgId`
- `envId`
- `apiId`
- `apiName`
- `apiInstanceName`
- `apiVersion`
- `receivedTs` (rfc3339)
- `repliedTs` (rfc3339, only available in response context)
- `runtimeVersion` (For example: `v1.7.0`)
- `hostId` (For example: `my-host`)
- `reqId` (Referred to as `traceId` in Flex Gateway logs)
- `requestDisposition` (`PROCESSED` or `VIOLATION`, only available in request context)
- `request.remoteAddress`
- `request.method`
- `request.requestPath`
- `request.headers` (all request headers)
- `upstream.uri` (URI of the upstream service)
- `upstream.headers` (headers sent to upstream service)
- `upstream.statusCode` (status code from upstream response, only available in response context)
- `violation.clientId` (Only available in response context)
- `violation.clientName` (Only available in response context)
- `violation.policyName` (Only available in response context)
- `violation.violationType` (`VIOLATION` or `ERROR`, only available in response context)

## [](#how-this-policy-works)How This Policy Works

Logging an outbound policy consists of the following sequence:

1. An outbound request is prepared to be sent to an upstream service.
2. The message is logged if these conditions are `true`:
    
    - The level and category of the log defined in the policy are included in the logger defined in the configuration file.
    - Either the conditional field of the policy is not set, or is set and the condition is met.
    - The `firstSection` flag is enabled (if logging before sending the request).
3. The request is sent to the upstream service.
4. The upstream service responds.
5. The message is logged if these conditions are `true`:
    
    - The level and category of the log defined in the policy are included in the logger defined in the configuration file.
    - Either the conditional field of the policy is not set, or is set and the condition is met.
    - The `secondSection` flag is enabled (if logging after receiving the response).
6. The response is returned to the client. Outbound Message Logging Policy does not interfere with the execution of any policy nor its flow.
7. The message appears in the application log.

## [](#logging-format)Logging Format

A message log uses this format:

`<date> [flex-gateway-envoy][<level>] wasm log <policy-name>.default.<api-name>.default.svc main: [req: <request uuid>] [accessLog] <message>`

- `policy-name`: displays the name of the policy binding.
- `api-name`: displays the name of the api instance.
- `request uuid`: displays a unique identifier for the request that triggered the message.

## [](#severity-levels)Message Logging Severity Levels

When you configure a Message Logging policy for your API instance, you can assign a severity level. Each severity level includes a specific set of information in the log report.

Log reports include the severity level you select and the following levels on the hierarchy.

For example, if you select DEBUG, the log reports include the DEBUG severity level as well as the INFO, WARN, and ERROR severity levels. However, if you select ERROR, the log reports include only error messages. The following table describes the type of information included in the logs for each severity level:

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 83.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Log Severity Level</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>DEBUG</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Tracing information used by application developers.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>INFO</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Informational messages that highlight the progress of the application.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>WARN</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Potentially harmful situations that indicate potential problems.</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>ERROR</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Events that prevent normal program execution but might allow the application to continue running.</p>
</div></div></td>
</tr>
</tbody>
</table>