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
Over 2 million developers have joined DZone.
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

  • Observability for Agents and Workflows: Tracing Prompts, Tool Calls, and Business Outcomes End-to-End
  • Intelligent Matching and Semantic Search for Marketplace Applications Using OpenAI and .NET
  • How to Format Articles for DZone
  • The Big Data Architecture Blueprint: Core Storage, Integration, and Governance Patterns
  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 user avatar
Nitish Jain
·
Updated Nov. 13, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
18.9K Views

Join the DZone community and get the full member experience.

Join For Free

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

The likes didn't load as expected. Please refresh the page and try again.

  • 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