DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Five Nonprofit & Charity APIs That Make Due Diligence Way Less Painful for Developers
  • Introduction to Couchbase for Oracle Developers and Experts: Part 4: Data Modeling
  • Introduction to Couchbase for Oracle Developers and Experts: Part 2 - Database Objects
  • Step-by-Step Guide to Use Anypoint MQ: Part 4

Trending

  • Why AI Agents Need a Shared Enterprise Ontology
  • Reusable Operational Playbooks With Agent Skills
  • The KV Cache Is Optional Now: What Mercury 3's 1000 tok/s Means for the Inference Serving Stack
  • Don't Adopt Anything Announced at re:Invent for 90 Days

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. DataWeave Logging — Print Logs From DataWeave2.0

DataWeave Logging — Print Logs From DataWeave2.0

This article is about printing the logs directly in the output console(after deployment) without using an additional logger component.

By 
Nitish Jain
·
Updated Nov. 13, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
19.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Hi Muleys,

This article is about printing the logs directly in the output console(after deployment) without using an additional logger component.

We know how to print the logs using the logger component but to print specific values or fields directly from DataWeave/Transform Message component will be more helpful and Dev-Friendly as Developers can print the specific values what they want. It is useful to print only required information rather than printing the whole data which may contain sensitive or PII information.

Example:  This example shows how to log the result of the CandidateInfo without changing any original values in the DataWeave.

DataWeave Code

Plain Text
xxxxxxxxxx
1
12
 
1
2.0
2
output application/json
3
var a = [{name: "Max", email: "[email protected]", phone: "91 0808907890", company: "MuleSoft"},{name: "Mule", email: "[email protected]", phone: "91 0808907890", company: "MuleSoft"}] 
4
5
--- 
6
a map 
7
{
8
"CandidateName": $.name,
9
"Contact": $.email,
10
"Company": $.company,
11
"Info": log("CandidateInfo" , $.name ++ " is working at " ++ $.company)
12
} 


Console Output

console output

Plain Text
xxxxxxxxxx
1
 
1
INFO  2020-10-30 18:41:07,700 [[MuleRuntime].uber.02: [dwllogger].dwlloggerFlow2.CPU_INTENSIVE @6b18ae54] [processor: ; event: 5f43bb20-1ab1-11eb-8bbb-8c164585008e] org.mule.weave.v2.model.service.DefaultLoggingService$: CandidateInfo - "Max is working at MuleSoft"
2
INFO  2020-10-30 18:41:07,703 [[MuleRuntime].uber.02: [dwllogger].dwlloggerFlow2.CPU_INTENSIVE @6b18ae54] [processor: ; event: 5f43bb20-1ab1-11eb-8bbb-8c164585008e] org.mule.weave.v2.model.service.DefaultLoggingService$: CandidateInfo - "Mule is working at MuleSoft"


Expression Output

JSON
xxxxxxxxxx
1
28
 
1
[
2
3
    {
4
5
        "CandidateName": "Max",
6
7
        "Contact": "[email protected]",
8
9
        "Company": "MuleSoft",
10
11
        "Info": "Max is working at MuleSoft"
12
13
    },
14
15
    {
16
17
        "CandidateName": "Mule",
18
19
        "Contact": "[email protected]",
20
21
        "Company": "MuleSoft",
22
23
        "Info": "Mule is working at MuleSoft"
24
25
    }
26
27
]
28


Conclusion

Using Log Function in DataWeave/Transform Message component, we filtered out the sensitive value and logged what we want, directly in the output Console.

Happy Learning!

Plain text Printing Console (video game CLI) Data (computing) dev JSON

Opinions expressed by DZone contributors are their own.

Related

  • Five Nonprofit & Charity APIs That Make Due Diligence Way Less Painful for Developers
  • Introduction to Couchbase for Oracle Developers and Experts: Part 4: Data Modeling
  • Introduction to Couchbase for Oracle Developers and Experts: Part 2 - Database Objects
  • Step-by-Step Guide to Use Anypoint MQ: Part 4

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook