5

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 ?

tortoise
  • 613
  • 1
  • 7
  • 19
  • I had a similar [question](http://stackoverflow.com/questions/36449186/ignore-and-log-csv-row-in-dataweave-if-condition-is-met) to this - not sure if the answer is relevant to your use case... – danw Apr 25 '16 at 12:40
  • You can use log function and official document is here- https://docs.mulesoft.com/dataweave/2.2/dw-core-functions-log – Anurag Sharma Feb 03 '22 at 11:38

5 Answers5

11

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

scorpion
  • 223
  • 3
  • 15
1

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?

Community
  • 1
  • 1
Manik Magar
  • 1,403
  • 2
  • 10
  • 20
1

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.

Srinivas
  • 92
  • 3
0

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

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.

agentv
  • 739
  • 1
  • 9
  • 21