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

Improve log mediator to support string templating #2230

Merged
merged 4 commits into from
Dec 3, 2024

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
@@ -288,6 +302,16 @@ public void setCategory(int category) {
}
}

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