Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log camel exchange body as string using log4j

I'm trying to log exchange body as a string using log4j.

<convertBodyTo id="_convertBodyTo1" type="java.lang.String"/>
<to id="_to1" uri="log:com.javarticles?level=INFO"/>

but it's not logging as string

15:09:05,403 | INFO  | qtp938841692-57  | javarticles                      |
198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | 
Exchange[ExchangePattern: InOut, BodyType: java.lang.String, Body: 
org.apache.cxf.jaxrs.impl.HttpHeadersImpl@52767902]

Do we have to make extra logic to log exchange body? And how do we log http headers?

like image 754
tvshajeer Avatar asked Dec 21 '16 10:12

tvshajeer


People also ask

How do you log the body in Apache Camel?

Logging message body with streaming The log DSL have overloaded methods to set the logging level and/or name as well. from("direct:start") . log(LoggingLevel. DEBUG, "com.

Does camel use log4j?

Apache Camel is using log4j for testing itself Apache Camel does use log4j during testing itself, and therefore you can find that we have been using log4j v2.

What is Exchange in Apache Camel?

Exchange is the container of a message and it is created when a message is received by a consumer during the routing process. Exchange allows different types of interaction between systems – it can define a one-way message or a request-response message.


1 Answers

If you only want to log the message body, then use

<log message="${body}"/>

The log endpoint logs a bunch of details by default, you can turn these on|off using the options listed: http://camel.apache.org/log

like image 67
Claus Ibsen Avatar answered Oct 09 '22 19:10

Claus Ibsen