5
votes

Just like we use

<xsl:message> 

inside XSL transformer and

system.out.println

for datamapper, do we have any logging mechanism for dataweave ? If not a direct component, do we have any other alternate mechanisms to achieve logging from inside dataweave ?

5
I had a similar question to this - not sure if the answer is relevant to your use case...danw

5 Answers

11
votes

In mule 3.8 you can do it like this ,mule allows logging in dataweave

 %dw 1.0 
 %output application/json
 --- 
 {   
   result: log("Logging the array",[1,2,3,4]) 
 }

you can refer the latest document for this here

1
votes

You can take a look at my answer here - https://stackoverflow.com/a/36458835/5616671.

If you want to log every record that is being processed by dataweave map, you can change the filter function to return true always and log value before returning.

BTW, What type of logging you want to do?

1
votes

For now the only way and best way to debug Dataweave is to use code on the lines given below. Value: log("This is Debugvalue",flowVars.company)

You can replace the flowVars.company with any of the values you want to pring during the runtime of application.

0
votes

Use the dataweave function log

Script

%dw 2.0
output application/json

var x = now()
---
log("Today is " ++ x)

Output

"Today is 2020-03-24T00:38:58.323Z"

Source: https://docs.mulesoft.com/mule-runtime/4.2/dw-core-functions-log

0
votes

At the current time (2021), you would be using DataWeave 2.x and there is a handy log function in the DW library.

You may use it like this:

%dw 2.0
output application/dw

var usermessage = "Bob was here"
---
log ("LOGGEDUSERMESSAGE",usermessage)

The output in the log will look like this:

INFO  2021-04-20 16:20 .... LoggingService$: LOGGEDUSERMESSAGE - "Bob was here"

In application however, log() resolves to the string version of the second argument. Or to say it another way, it passes the second argument along untouched, but it logs both the tag you provide in the first arg separated from the second arg by a dash.

Take note, this is not the logging level. It is an internal tag that the application owner can use to filter log entries.