Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 4 of 6

Logging without leaking data

9 min

Listen to this lesson

0:00 / 5:21

"Script to log payload" is one of the most searched Cloud Integration topics, and one of the most dangerous habits. A payload attached to every message processing log (MPL) is convenient in test and a liability in production: it fills tenant storage, and it copies personal and commercial data into a place with different access rules. Learn the API, then learn when not to use it.

The MessageLog API

In a script, the variable messageLogFactory gives you the log: def messageLog = messageLogFactory.getMessageLog(message). Check for null before using it. The idiomatic one-liner from SAP's documentation attaches the body: messageLogFactory.getMessageLog(message)?.addAttachmentAsString('Payload', message.getBody(String), 'text/plain'). The attachment appears on the Attachments tab in Monitor Message Processing.

MethodUseVisibility
addAttachmentAsString(name, text, mediaType)A longer document, such as a payload extractAttachments tab of the MPL
setStringProperty(name, value) (also Integer, Long, Boolean, Float, Double, Date)A short value, one or a few wordsOnly when the log level is Debug or Trace
addCustomHeaderProperty(name, value)A business key you want to search forPersisted and searchable in monitoring

MessageLog methods and where their output shows up.

Make messages findable instead of dumping them

Support rarely needs the whole payload. They need to find the right message. Two tools do that without copying data. Set the header SAP_ApplicationID to the business key, for example PO number 4500000187; monitoring shows it as the Application Message ID and lets you search by it. Or add custom header properties: messageLog?.addCustomHeaderProperty('PurchaseOrder', po). Contoso's rule for the migration: every flow sets one searchable business key, and nothing else is logged by default.

Choose the lightest logging that answers the support question; payload attachments are the exception, not the default.
The Sign-Off Table · thesignofftable.com/academy/sap-pim-202

Switch it, mask it, limit it

SAP's guidelines say to put logging behind a switch, using the flow's log level or an externalized parameter. A simple pattern: a Content Modifier sets the property logPayload from an externalized parameter, and the script attaches only when it is true: if (message.getProperty('logPayload') == 'true') { ... }. Each tenant can then set its own value at configuration time, without changing the flow.

Mask before you attach. Supplier invoices from Lakeside contain bank details; customer orders from Great Lakes Fleet Services can carry contact names and e-mail addresses. Replace those values in the copy you log, not in the message you send. And remember the limit: SAP warns that with high volumes, MPL attachments can fill the tenant's disk space and open the circuit breaker for persistence.

Where Trace fits

The Trace log level records message content at each step of a flow, which makes it the best debugging tool Cloud Integration has and the reason it is restricted. SAP limits how long Trace stays active, and viewing trace content needs extra authorization. Contoso's rule: Trace freely on CMC_TEST while building, and in production only for a named incident, for the shortest time, with Nadia's agreement. A script never needs to copy what Trace already shows for that one investigation.

Default: no payloadBusiness key in SAP_ApplicationID or a custom header property
Debug or TraceShort values via setStringProperty, visible only at those log levels
Switched attachmentMasked payload extract, enabled per tenant by an externalized parameter
NeverCredentials, keys or tokens in headers, properties or logs
Contoso's logging layers, from the default to the never-allowed.
The Sign-Off Table · thesignofftable.com/academy/sap-pim-202

A masking helper is a good first entry for a shared script collection (lesson 5): one function that takes the payload copy and replaces agreed fields, such as bank account numbers, e-mail addresses and contact names, with fixed placeholders. Every flow that logs anything calls the same function, so Nadia reviews the masking rules once instead of in every script.

Credentials don't belong in scripts

SAP's rules are direct: don't read credentials in a script to write them into HTTP headers; use adapters with User Credentials artifacts. Where a script really must use a secure parameter, don't store it in a header or property, because features such as tracing can show headers and properties in clear text. Nadia, Contoso's security and GRC lead, reviews every script that touches security material.

What would you do?

Two weeks after an interface moves from XP1, support asks Theo to switch on payload attachments for every message in production "just in case". Ana in accounts payable has reported one Lakeside invoice that didn't post. What should Theo do?

Key points
  • Get the log with messageLogFactory.getMessageLog(message) and check for null.
  • Make messages findable with SAP_ApplicationID or addCustomHeaderProperty instead of attaching payloads.
  • setStringProperty values show only at Debug or Trace; attachments are switched, masked and rare.
  • Never put credentials into headers, properties or logs.

Check your understanding · not graded

Lesson check

  1. 1. When are values written with <code>messageLog.setStringProperty</code> visible in the MPL?

  2. 2. Support wants to find messages by PO number without seeing payloads. What should the script do?

  3. 3. Which risk does SAP name for writing payloads as MPL attachments at high volume?

  4. 4. Why shouldn't a script store a secure parameter in a header or property?