Skip to content

Conversation

@SanojPunchihewa
Copy link
Contributor

@SanojPunchihewa SanojPunchihewa commented Nov 6, 2024

Purpose

In the current log mediator, the user needs to add a property and use XPATH concatenations to define a log message. With this improvement, the user can define a string template for the log message. In addition to the log message, the user can add additional properties to be logged.

<log category="INFO">
    <message>Test clone path 1 "logging" ${var.var1}</message>
</log>
<log category="INFO">
    <message>Test message "logging" ${var.var1}</message>
    <property name="var2" value="test-prop1"/>
    <property name="server-header" expression="${headers.Server}"/>
</log>

To maintain backward compatibility when the user has set a level, the message will be printed in addition to the content printed according to level

// Extract the expression inside ${...}
String placeholder = matcher.group(1);
SynapseExpression expression = new SynapseExpression(placeholder);
String replacement = expression.stringValueOf(synCtx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the stringValueOf fails we get the value "unknown" should we print a warn log outside the while loop saying processed template might have an incorrect result since evaluation of some expressions failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot distinguish the unknown at the mediator level. We may need to print the warn log at the evaluation.

@SanojPunchihewa SanojPunchihewa force-pushed the log-mediator branch 2 times, most recently from 082f1bf to c1e4644 Compare November 22, 2024 06:55
}

public String getMessageTemplate() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why an additional new line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's added by the wso2_code_style for idea.

}

public void setMessageTemplate(String messageTemplate) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@SanojPunchihewa SanojPunchihewa merged commit a460488 into wso2:master Dec 3, 2024
1 of 2 checks passed
senthuran16 pushed a commit to senthuran16/wso2-synapse that referenced this pull request Jun 16, 2025
[4.2.0] Add a null check for response message context to skip engaging interceptors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants