I need to print a portion of the String variable value to the Mule console using Mule <logger . Not sure of it is possible to use substring function within the logger. However when I tried the following syntax I get the error that reference to the substring function not found.
Syntax Tried: (Note: square brackets after # are getting removed from the post but I did use those)
"<logger message=" #substring(vars.topicDetails, 10, 50)" level="INFO"/>"
"<logger message=" #vars.topicDetails.substring(10, 50)" level="INFO"/>"
<logger message=" #import * from dw::core::String --- substring(vars.topicDetails,10.50)" level="INFO"/>
<logger message=" #dw::core::String::substring(vars.topicDetails,10.50)" level="INFO"/>
Error: Unable to resolve reference of: 'substring' . at 1 : 1"
I am using Mule 4.6 version. Note that I am looking for DW script, I can very well do it through DW script but my requirement is to print on Mule console using Mule "<logger".
Thanks.
Confirm Variable Existence and Type: Add this logger before using substring to inspect the value of vars.topicDetails:
code<logger message="#[vars.topicDetails]" level="INFO" />
If null or not a string, fix how vars.topicDetails is being set.
Test with Static Data: Replace vars.topicDetails with a hardcoded string to isolate the issue:
code<logger message="#['This is a test string'.substring(10, 50)]" level="INFO" />
If this works, the issue is with vars.topicDetails.
Try below syntax:
<logger message="#(vars.topicDetails default '').substring(10, min(50, (vars.topicDetails default '').length()))" level="INFO" />