2

i have a problem with logging SLF4J at Apache Kafka. I want to use Tomcats Servlet Container Catalina in connection with Apache Kafka. My Java application has to be integrated into a BPM process from Camunda. The integration of Java coding worked so far also - without the integration of an Apache Kafka Producer. If I integrate this into a Camunda process I get this error:

java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/ParallelWebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:418)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at org.apache.kafka.clients.CommonClientConfigs.<clinit>(CommonClientConfigs.java:32)
at org.apache.kafka.clients.producer.ProducerConfig.<clinit>(ProducerConfig.java:305)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:304)

As far as I understand the error, Camunda and Apache Kafka are trying to call the SLF4J logger, aren't they? But in my case I need the Camunda logger. So I would like to disable Apache Kafka logging to work around the problem. So far my simple Kafka Producer looks like this:

String topicName = "camunda";
String test = "test123";
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092,localhost:9093");
props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");
                
Producer<String, String> producer = new KafkaProducer <>(props);
ProducerRecord<String, String> record = new ProducerRecord<>(topicName,test);
producer.send(record);
producer.close();

is there a way to solve this problem? Unfortunately, I couldn't find any entries on how to disable the Kafka Logger, or is the problem somewhere else?

Many thanks in advance

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
Leon
  • 371
  • 4
  • 11
  • 1
    slf4j is only a facade to a real logging framework. For example, Kafka brokers use Log4J, so you need to find the configurations for this Camuda thing and figure out how to tune the log levels/packages from there. Alternatively, in Maven, for example, you can exclude sl4jj from the kafka-clients library – OneCricketeer Oct 18 '18 at 20:04
  • I'm not really sure which applied to your use case, but feel free to show a solution you came up with below – OneCricketeer Oct 19 '18 at 13:49
  • Here is my Answer to completely disable kafka logging: https://stackoverflow.com/a/62401824/5370480 – Dean Jain Jun 16 '20 at 05:59

1 Answers1

4

The approach to disable SFL4J-Logger for the Maven dependency on apache Kafka worked fine for me. I changed my pom file as follows:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.0.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
     </exclusions>
</dependency>
Leon
  • 371
  • 4
  • 11