0

My complete error is

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.

I have checked other answers and found that the issue is usually lack of framework jars for slf4j.jar - Hence I included dependencies logback-core and logback-classic and also checked the versions are non-beta versions, as you can see in my build.gradle file below

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'
}

repositories {
    // Use JCenter for resolving dependencies.
    jcenter()
}

dependencies {
    // Use JUnit test framework.
    testImplementation 'junit:junit:4.13'

    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:29.0-jre'
    
    // https://mvnrepository.com/artifact/ch.qos.logback/logback-core
    implementation 'ch.qos.logback:logback-core:1.2.5'
    
    // https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
testImplementation 'ch.qos.logback:logback-classic:1.2.5'
    
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-api
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'

// https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14
//testImplementation group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.21' 
    
    
}

My java file is

package Sample2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogText {

Logger logger = LoggerFactory.getLogger(JavaApplication.class);

public void logthetext() {
    
    logger.debug("Debug Statements");
    
}}

And my logback.xml is

    <?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
  
</configuration>

I am not sure where I am going wrong here.

Adharsh
  • 31
  • 1
  • 1
  • 5
  • 1
    I think you do not need to depend on logback-core explicitly as it is a dependency of logback-classic. If your Class is used during (non-test) runtime and lockback core is not provided by a container you should set the scope of logback-classic to implementation. – DrHopfen Nov 04 '21 at 13:59

0 Answers0