logging from inside dataweave
Asked Answered
F

5

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 ?

Frameup answered 25/4, 2016 at 9:26 Comment(2)
I had a similar question to this - not sure if the answer is relevant to your use case...Okay
You can use log function and official document is here- docs.mulesoft.com/dataweave/2.2/dw-core-functions-logPiwowar
Y
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

Yuma answered 31/5, 2016 at 10:31 Comment(0)
M
1

You can take a look at my answer here - https://mcmap.net/q/1923229/-ignore-and-log-csv-row-in-dataweave-if-condition-is-met.

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?

Molybdenous answered 25/4, 2016 at 13:21 Comment(0)
V
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.

Vulvitis answered 21/2, 2018 at 6:26 Comment(1)
This is a valid answer for DataWeave 1.xBlockage
H
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

Handhold answered 24/3, 2020 at 0:43 Comment(0)
B
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.

Blockage answered 20/4, 2021 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.