How to configure route tracing in Apache Camel >= 3?

Viewed 2771

I'm trying to migrate from Camel 2.X to 3.X and have run in to a question about logging the routing trace. Previously I have configured it like this in my application context xml-file:

<bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer">
    <property name="traceExceptions" value="false" />
    <property name="traceInterceptors" value="true" />
    <property name="logLevel" value="DEBUG" />
    <property name="logName" value="com.mycompany.routing.trace" />
</bean>

<bean id="traceFormatter" class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
    <property name="showBody" value="true" />
    <property name="maxChars" value="0" />
</bean>

But that obviously does not work anymore. From the migration guide on the Camel website:

"A new tracer has been implemented and the old tracer has been removed. The new tracer logs messages at the org.apache.camel.Tracing logger name which is hardcoded. The format of the output is also updated to make it better. The tracer can be customized."

If I set .tracing() at the start of my routes it does log the trace. The name is hardcoded which is fine, but I would like to change the level from INFO to DEBUG among other things.

Does anyone know where to find information on how to configure this "new" tracer (preferrably in an applicationContext.xml file)? Or anywhere else, maybe in the Java DSL route? Or if it is even possible?

Thanks!

1 Answers

Logging level of DefaultTracer cannot be changed by configuration. You need to implement customized Tracer and bind this implementation to registry.

Tracer:

public class TracerCustom extends DefaultTracer {
    private static final Logger LOG = LoggerFactory.getLogger("com.stackoverflow.camel.TracerCustom");

    @Override
    protected void dumpTrace(String out) {
        LOG.debug(out);
    }
    // Customize other methods if needed
}

Spring context:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <bean class="com.stackoverflow.camel.TracerCustom" />

  <camelContext id="tracerCamelContext" xmlns="http://camel.apache.org/schema/spring">
    <route trace="true">
      <from uri="timer:test"/>
      <to uri="log:test"/>
    </route>
  </camelContext>

</beans>
Related