如何在 Apache Camel >= 3 中配置路由跟踪?

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

我正在尝试从 Camel 2.X 迁移到 3.X 并让 运行 回答有关记录路由跟踪的问题。 以前我在我的应用程序上下文中这样配置它 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>

但这显然不再有效了。 来自 Camel 网站上的迁移指南:

"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."

如果我在我的路线开始时设置 .tracing(),它会记录跟踪。名称是硬编码的,这很好,但我想将级别从 INFO 更改为 DEBUG 等等。

有谁知道在哪里可以找到有关如何配置此 "new" 跟踪器的信息(最好在 applicationContext.xml 文件中)?或者在其他任何地方,也许在 Java DSL 路线中?或者甚至可能吗?

谢谢!

DefaultTracer cannot be changed by configuration. You need to implement customized Tracer 的日志记录级别并将此实现绑定到注册表。

示踪剂:

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

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

Spring 上下文:

<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.Whosebug.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>