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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Designing a Java Connector for Software Integrations
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • Unlocking the Benefits of a Private API in AWS API Gateway

Trending

  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • How To Develop a Truly Performant Mobile Application in 2025: A Case for Android
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Avoid Printing Exception Stack Traces

How to Avoid Printing Exception Stack Traces

Stack traces have been around in the software development world for quite some time now, but it can't be ignored that they can create major issues for Operations teams.

By 
Alagappan Veerappan user avatar
Alagappan Veerappan
·
Feb. 12, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
14.0K Views

Join the DZone community and get the full member experience.

Join For Free

This article explains how to avoid printing exception stack traces when running APIs that are configured with Mule EE runtime and Mule API gateway runtime.

Printing exception stack traces is not a new concept in the software world. However, it's still important to remember that if the stack traces are not handled properly, they will end up accumulating in log files. This can create issues for the Operations team when they want to manage higher environments.

We will discuss here some steps for both Mule EE and API gateway runtimes. The latest Mule EE runtime is 3.8.2. Older versions (< 3.8.X) have Mule EE runtime and API gateway runtime separately.

API gateway runtime is a feature to support the sharing of connectors across the projects deployed in the domain. However, there's a lot more to it than that. To know more about API gateway runtime, check out this documentation from MuleSoft. Mule EE 3.8.2 runtime has unified both API gateway and Mule core runtime.

Avoid Exception Stack Traces With Mule 3.8 Runtime

Configure the logException attribute as false in the catch-exception-strategy block. By default, logException is set as true, which enables Mule to print an exception stack trace. 

Here's an example snippet:

<catch-exception-strategy doc:name="Catch Exception Strategy" logException="false">
 <logger level="ERROR" doc:name="exceptionLogger" message="Exception message is ... #[exception.message]"/>
  <set-variable variableName="exceptionMessage" value="#[exception.message]" doc:name="Set exceptionMessage"/>
  <set-payload value="{  errors: {     errorCode: #[message.inboundProperties.'http.status'],     errorMessage: #[flowVars.exceptionMessage]  }  }" doc:name="Set Exception Payload"/>
</catch-exception-strategy>

Avoid Exception Stack Traces With Mule API Gateway Runtime

Mule API gateway runtime coupled with 3.7.x or Mule runtime (< 3.8.x) does not have the logException attribute defined in its implementation. The solution to avoid stack trace is below.

Define a logger inside the catch-exception-strategy and set the category, along with setting the level to ERROR.

Here's an example snippet:

<catch-exception-strategy doc:name="Catch Exception Strategy">
 <logger level="ERROR" doc:name="exceptionLogger" message="Exception message is ... #[exception.message]" category="com.project.stacktrace"/>
  <set-variable variableName="exceptionMessage" value="#[exception.message]" doc:name="Set exceptionMessage"/>
  <set-payload value="{  errors: {     errorCode: #[message.inboundProperties.'http.status'],     errorMessage: #[flowVars.exceptionMessage]  }  }" doc:name="Set Exception Payload"/>
</catch-exception-strategy>

Configure the below log4j settings in the project's log4j2.xml file as shown below:

<AsyncLogger name="org.mule.exception.CatchMessagingExceptionStrategy" level="FATAL"/>
<AsyncLogger name="com.project.stacktrace" level="ERROR"/>

I have demonstrated the above steps this a video tutorial.

We will continue expanding this example with error handling on Anypoint Studio in the next article.

Printing API

Opinions expressed by DZone contributors are their own.

Related

  • Designing a Java Connector for Software Integrations
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • Unlocking the Benefits of a Private API in AWS API Gateway

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: