Loading
 
What's Next: View All Tutorial →

Camel with SL4J for logging to avoid Failed to load class "org.slf4j.impl.StaticLoggerBinder"

In this article you will learn how to integrate sl4j simple logger and to use log() function. The camel dependency using the SL4J library. By default, SL4J library using the NOP logger implementation. Exception Message   SLF4J...

Published Date: 03/06/2015  Last Modified Date: 03/06/2015    New Post



In this article you will learn how to integrate sl4j simple logger and to use log() function.


The camel dependency using the SL4J library.

By default, SL4J library using the NOP logger implementation.



Exception Message

 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
We need to add the lo4j.properties to the sl4j or we can simply add this SL4J-simple jar dependency. This take the default debug mode logger settings
 

Add Dependency

 
<dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.15.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.5</version>
        </dependency>
    </dependencies>


Camel Program

 
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.catchmycity.camelwithsl4j;

import org.apache.camel.CamelContext;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

/**
 *
 * @author catchmycity
 *
 */
public class CamelProcessor {

    public static void main(String args[]) throws Exception {

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {

                from("direct:a").log("It is a router a. body - ${body} - header - ${header.foo}").end();
                from("direct:b").log("It is a router b. body - ${body} - header - ${header.foo}").end();
            }
        });
        context.start();
        ProducerTemplate producer = context.createProducerTemplate();

        producer.sendBodyAndHeader("direct:a", ExchangePattern.InOut, "body message a", "foo", "bar");
        //OutPut:
        //route1 - It is a router a. body - body message a - header - bar

        producer.sendBodyAndHeader("direct:b", ExchangePattern.InOut, "body message b", "foo", "cheese");

        //Output:
        //route2 - It is a router b. body - body message b - header - cheese
    }

}


Keyword to know


log() - to print logger


Download

https://github.com/Catchmycity/ApacheCamel/tree/master/ApacheCamel/CamelWithSl4j
 
Awaiting for Administrator approval





Tags: Basic

← Back to list


Related Post




×