Logging errors

Camel makes it easy to ensure that all uncaught exceptions are logged in a specific way using the logging error handler. You can set this mechanism both globally (at the Camel context level), and at the route level, to log all unhandled exceptions using a log name and level.

This recipe will show you how to use the LoggingErrorHandler error handler to log errors caught by Camel at runtime.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.error.logging package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with logging.

How to do it...

In the XML DSL, define an errorHandler element within the camelContext element, and reference the error handler's id in the errorHandlerRef ...

Get Apache Camel Developer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.