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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

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

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