Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: CAMEL-944

...

You can enable or disable the Tracer's logging dynamically, by calling the tracer's setEnabled method.

Options

Trace has been improved in Camel 1.5 to be more configurable with these options:

Option

Default

Description

formatter

 

Sets the Trace Formatter to use.

enabled

true

Flag to enable or disable this tracer

level

INFO

The logging level to use: FATAL, ERROR, WARN, INFO, DEBUG, TRACE

traceFilter

null

An exchange Predicate to filter the tracing.

traceInterceptors

false

Flag to enable or disable tracing of interceptors

traceExceptions

true

Flag to enable or disable tracing of thrown exception during processing of the exchange

Formatting

The tracer formats the execution of exchanges to log lines. They are logged at INFO level in the log category: org.apache.camel.processor.interceptor.TraceInterceptor.
The tracer uses by default TraceFormatter to format the log line.

TraceFormatter has the following options:

Option

Default

Description

showBreadCrumb

true

Outputs the unique unit of work for the exchange. To be used for correlation so you can identify the same exchange.

showNode

true

The destination node.

showExchangeId

false

To output the unique exchange id. Currently the breadcrumb is sufficient.

showProperties

true

Output the exchange properties

showHeaders

true

Output the in message headers

showBodyType

true

Output the in body Java type

showBody

true

Output the in body

showExchangePattern

true

Camel 1.5: Output the exchange pattern

showException

true

Camel 1.5: Output the exception if the exchange has failed

Example:

Code Block
ID-claus-acer/36904412-12144583157181222625653890/2-0 -> node3 To[to(mock:a] InOnly Properties:{CamelCauseException=null})                     , Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London

Wiki Markup
{{ID-claus-acer/3690-1214458315718/2-0}} is the breadcrumb with the unique correlation id.
{{node3}} is the id of the node in the route path. Is always shown.
{{To\[mock:a\]}} is the destination node.
{{InOnly}} is the exchange pattern. Is always shown.
Then the rest is properties, headers and the body.

...

Running the test we get the trace information logged at INFO level:

Code Block
2008-06-26 07:31:55,828 [main           ] INFO  TraceInterceptor               - ID-claus-acer/36904412-12144583157181222625653890/2-0 -> node5 Interceptor[Delegate(Pipeline[DeadLetterChannel[Delegate(TraceInterceptor[Processor[MyProcessor]]), ...
2008-06-26 07:31:55,843 [mainprocess(MyProcessor)           , Pattern:InOnly  ] INFO  TraceInterceptor       , Headers:{to=James} , BodyType:String , Body:Hello London 
INFO  TraceInterceptor        - ID-claus-acer/36904412-12144583157181222625653890/2-0 -> node2 Processor[MyProcessor] InOnly Properties:{CamelCauseException=null} Headers:{to=James} Body:Hello London
2008-06-26 07:31:55,843 [main  to(mock:a)            ] INFO  TraceInterceptor               - ID-claus-acer/3690-1214458315718/2-0 -> node3 To[mock:a] InOnly Properties:{CamelCauseException=null}, Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London
2008-06-26 07:31:55,843 [main           ]  
INFO  TraceInterceptor               - ID-claus-acer/36904412-12144583157181222625653890/2-0 -> node4 To[to(mock:b])  InOnly Properties:{CamelCauseException=null} Headers:{to=James} Body:Hello London
2008-06-26 07:31:55,859 [main           ] INFO , TraceInterceptorPattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London 
INFO  TraceInterceptor     - ID-claus-acer/36904412-12144583157181222625653890/2-1 -> node5 Interceptor[Delegate(Pipeline[DeadLetterChannel[Delegate(TraceInterceptor[Processor[MyProcessor]]), ...
2008-06-26 07:31:55,859 [mainprocess(MyProcessor)           , Pattern:InOnly ] INFO  TraceInterceptor          , Headers:{from=Claus} , BodyType:String , Body:This is Copenhagen calling 
INFO  TraceInterceptor     - ID-claus-acer/36904412-12144583157181222625653890/2-1 -> node2 Processor[MyProcessor] InOnly Properties:{CamelCauseException=null} Headers:{from=Claus} Body:This is Copenhagen calling
2008-06-26 07:31:55,875 [mainto(mock:a)                     ], INFOPattern:InOnly  TraceInterceptor          , Headers:{from=Claus} , BodyType:String , Body:This is Copenhagen calling 
INFO  TraceInterceptor     - ID-claus-acer/36904412-12144583157181222625653890/2-1 -> node3 To[to(mock:a]b) InOnly Properties:{CamelCauseException=null} Headers:{from=Claus} Body:This is Copenhagen calling
2008-06-26 07:31:55,875 [main           ] INFO  TraceInterceptor               - ID-claus-acer/3690-1214458315718/2-1 -> node4 To[mock:b] InOnly Properties:{CamelCauseException=null}, Pattern:InOnly , Headers:{from=Claus} , BodyType:String , Body:This is Copenhagen calling 

Configuring from Java DSL

...

Code Block
    public void configure() throws Exception {
        // add tracer as an interceptor so it will log the exchange executions at runtime
        // this can aid us to understand/see how the exchanges is routed etc.
        Tracer tracer = new Tracer();
        tracer.getFormatter().setShowBreadCrumb(false);
        tracer.getFormatter().setShowNode(false);
        ...
        getContext().addInterceptStrategy(tracer);

Using predicates to filter exchanges

Available as of Camel 1.5
In the code below we want the tracer only to trace if the body contains the text London. As this is just an example can of course set any Predicate that matches your criteria:

Code Block
java
java

    Tracer tracer = new Tracer();
    // set the level to FATAL so we can easily spot it
    tracer.setLevel(LoggingLevel.FATAL);
    // and only trace if the body contains London as text
    tracer.setTraceFilter(body().contains(constant("London")));
    // do not show exchange pattern
    tracer.getFormatter().setShowExchangePattern(false);

Enabling from Spring XML

...