我的完整错误是
SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。
SLF4J:默认为无操作(NOP)记录器实现
SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder。
我检查了其他答案,发现问题通常是缺少 slf4j.jar 的框架 jar - 因此我包含依赖项 logback-core 和 logback-classic 并检查了版本是非 beta 版本,正如你在我的构建中看到的那样.gradle文件如下
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'
}
我的java文件是
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");
}}
我的 logback.xml 是
<?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>
我不确定我在哪里出错了。