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
attribute of the camelContext
element. The type
attribute of the errorHandler
element must be set to "LoggingErrorHandler"
. You can optionally set the level
(defaults to ERROR
), and logName
(defaults to Logger
) attributes....