Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update log mediator for 4.4.0 version #1156

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 30 additions & 43 deletions en/docs/reference/mediators/log-mediator.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Log Mediator

The **Log mediator** enables the logging of messages as they flow through mediation sequences. It helps in debugging and tracking messages by printing message content, properties, and other relevant information to the console or a log file. It can be added at any point in the flow.
The **Log mediator** enables the logging of messages as they flow through mediation sequences. It helps in debugging and tracking messages by printing message content, variables, properties, and other relevant information to the console or a log file. It can be added at any point in the flow.

For more information on logging, see [Monitoring Logs]({{base_path}}/observe-and-manage/classic-observability-logs/monitoring-logs/).

## Syntax

```xml
<log [category="INFO|TRACE|DEBUG|WARN|ERROR|FATAL"] [level="custom|full|simple|headers"] [separator="string"]>
<log [category="INFO|TRACE|DEBUG|WARN|ERROR|FATAL"] [separator="string"]>
<message></message>
<property name="string" (value="string" | expression="expression")/>+
</log>
```
Expand All @@ -26,7 +27,7 @@ follows.
</thead>
<tbody>
<tr class="odd">
<td><strong>Category</strong></td>
<td><strong>Log Category</strong></td>
<td><p>This parameter is used to specify the log category. The following log levels correspond to the Micro Integrator service level logs.</p>
<ul>
<li><strong>INFO</strong> - provides informational messages that highlight the progress of the application at a coarse-grained level.</li>
Expand All @@ -38,29 +39,14 @@ follows.
</ul></td>
</tr>
<tr class="even">
<td><strong>Message</strong></td>
<td>
<p><strong>Level</strong></p>
</td>
<td>
<p>This parameter is used to specify the log level. The possible values are as follows.</p>
<ul>
<li><strong>Custom</strong> : If this is selected, only the properties added to the Log mediator configuration will be logged.</li>
<li><strong>Full</strong> : If this is selected, all the standard headers logged at the <strong>Simple</strong> level as well as the full payload of the message will be logged. This log level causes the message content to be parsed and hence incurs a performance overhead.</li>
<li><strong>Simple</strong> : If this is selected, the standard headers (such as <code>To</code>, <code>From</code>, <code>WSAction</code>, <code>SOAPAction</code>, <code>ReplyTo</code>, and <code>MessageID</code>) will be logged.</li>
<li><strong>Headers</strong> : If this is selected, all the SOAP header blocks will be logged.</li>
</ul>
<p>The properties included in the Log mediator configuration will be logged regardless of the log level selected.</p>
</td>
</tr>
<tr class="odd">
<td><strong>Separator</strong></td>
<td>
<p>This parameter specifies the value used to separate attributes in the log. By default, the separator is a comma (<code>,</code>).</p></td>
<p>This parameter is used to define a log message. You can embed <a href="{{base_path}}/reference/synapse-properties/synapse-expressions">Synapse Expressions</a> in the template to generate the log message.</p></td>
</tr>
</tbody>
</table>

You can add properties inside the Log mediator to log additional information. The parameters available to configure a property are as follows:
You can use the <strong>Additional Parameters</strong> section to log additional information. The configurations available under <strong>Additional Parameters</strong> section of the Log mediator are as follows.

<table>
<thead>
Expand All @@ -71,48 +57,49 @@ You can add properties inside the Log mediator to log additional information. Th
</thead>
<tbody>
<tr class="odd">
<td><strong>Property Name</strong></td>
<td>The name of the property to be logged.</td>
</tr>
<tr class="odd">
<td><strong>Value/Expression</strong></td>
<td><p>Based on the use case you can select either value or expression.</p>
<td><strong>Parameters</strong></td>
<td><p>This is used to specify the key value pairs to be logged. You can use the <code>Add Parameter</code> option to add a new parameter.
<ul>
<li><strong>Value</strong>: If this is selected, a static value would be considered as the property value and this value should be entered in the <strong>Value/Expression</strong> parameter.</li>
<li><p><strong>Expression</strong>: If this is selected, the property value will be determined during the runtime by evaluating an expression. You can refer to <a href="{{base_path}}/reference/synapse-properties/expressions">Expressions</a>.</p></li>
</ul></td>
<li><strong>Name</strong> - The name of the parameter to be logged.</li>
<li><strong>Value</strong> - Based on the use case you can either have a static value or an <a href="{{base_path}}/reference/synapse-properties/synapse-expressions">expression</a>.</li>
</ul></p></td>
</tr>
<tr class="even">
<td><strong>Parameter Separator</strong></td>
<td>
<p>This parameter specifies the value used to separate parameters in the log. By default, the separator is a comma (<code>,</code>).</p></td>
</tr>
</tbody>
</table>

## Examples

### Use full log
### Using a message template

In this example, everything is logged including the complete message.
In this example, we define a message template using [Synapse Expressions]({{base_path}}/reference/synapse-properties/synapse-expressions).

```xml
<log category="INFO" level="full"/>
<log category="INFO">
<message>Processing user details : ${payload.user} with Purchase data : ${var.purchaseDetails}</message>
</log>
```

A sample log output:
```xml
[2024-09-09 15:23:03,998] INFO {LogMediator} - {api:StockQuoteAPI} To: /stockQuote/getQuote, MessageID: urn:uuid:1f871a99-c7cc-4497-a767-945e4d5fd2c8, correlation_id: 1f871a99-c7cc-4497-a767-945e4d5fd2c8, Direction: request, Payload: { "symbol" : "IBM"}
[2024-09-09 15:23:03,998] INFO {LogMediator} - {api:StockQuoteAPI} Processing user details : {"firstName":"Johne", "lastName": "Doe"} with Purchase data : {"itemCode": 8987, "price": 45}
```

### Use custom logs
### Using parameters in addition to message template

In this example, the log level is `custom`. A property
with an XPath expression which is used to get a stock price from a
message is included. This results in logging the stock price which is a
dynamic value.
In this example, we define parameters in addition to the message.

```xml
<log category="INFO" level="custom">
<property name="text" expression="fn:concat('Stock price - ',get-property('stock_price'))"/>
<log category="INFO">
<message>Processing user details : ${payload.user} with Purchase data : ${var.purchaseDetails}</message>
<property name="endpoint" expression="${var.endpointName}"/>
</log>
```
A sample log output:
```xml
[2024-09-09 15:25:20,891] INFO {LogMediator} - {api:StockQuoteAPI} text = Stock price - 125.00
```
[2024-09-09 15:23:03,998] INFO {LogMediator} - {api:StockQuoteAPI} Processing user details : {"firstName":"Johne", "lastName": "Doe"} with Purchase data : {"itemCode": 8987, "price": 45}, endpoint = PurchaseEP
```