How to add logger in Apache Camel routes

Yes, we can log messages from Camel route, and can define different log levels for each log message.

In order to add logger, first you need to add required additional dependencies to your application.


Then add or log4j.xml to the application classpath.

log4j.rootLogger=INFO, out
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n

Add below line to your properties file to enable debugging of Camel messages


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"

  <appender name="console" class="org.apache.log4j.ConsoleAppender">
      <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
      value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
    <level value="DEBUG" />
    <appender-ref ref="console" />

Now in camel routes, use below code snippets to add loggers in camel routes

.log(LoggingLevel.DEBUG, "This is an DEBUG log message")
.log(LoggingLevel.INFO, "This is an INFO log message")
.log(LoggingLevel.ERROR, "This is an ERROR log message")

That’s it. Your application now will start logging messages from camel routes. You can add more log4j attributes as required to this to customized for your application.

Leave a Reply

Your email address will not be published. Required fields are marked *