Logging issues on an apache camel spring boot aplication

40 Views Asked by At

I have inherited an apache camel spring boot application and I am having issues with logging. The route components are annotated with lombok.extern.slf4j.Slf4j annotation. The normal logs are working fine, but the log in the route is not working:

@Slf4j
@Component
public class MyRoute extends RouteBuilder {
    @Override
    public void configure() {
         log.info("Working normally");

         from("direct:source")
             .log("Not working")
             .to("direct:target");
    }
}

The contents of the logback.xml file are:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/Logging/Logback/base.xml"/>
    <logger name="com.myapp" level="INFO"/>
    <logger name="com.apache.camel" level="INFO"/>
    <logger name="org.springframework.boot" level="INFO"/>
    <logger name="org.springframework.web" level="INFO"/>
    <logger name="com.netflix" level="INFO"/>
    <logger name="com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver" level="WARN"/>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>$(APP_HOME}/logs/myapp-${spring.profiles.active).log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRolling Policy">
            <fileNamePattern>$[APP_HOME}/logs/archive/myapp-${spring.profiles.active]-%d{yyyy-MM-dd).log.gz</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
    </appender>
    <root level="ERROR">
        <appender-ref ref="FILE"/>
    </root>
</configuration>

So, the log in the route is not working. If, I do an inline processor in the route and use the slf4j log.info() to log, it works ok.

2

There are 2 best solutions below

0
Claus Ibsen On

The log in the Camel route (not working) uses the route_id as the logger name. You can change that to a name of your choosing. The log.info is directly calling the logger framework and its common to use the classname as the log name.

See the Log EIP docs https://camel.apache.org/components/4.4.x/eips/log-eip.html

0
nikolakoco On

Adding the slf4j instance as a second parameter fixed the issue:

@Slf4j
@Component
public class MyRoute extends RouteBuilder {
  @Override
  public void configure() {
     log.info("Working normally");

     from("direct:source")
         .log(LoggingLevel.INFO, log, "Working normally")
         .to("direct:target");
}

}