我很难在IntelliJ中用Gradle配置SLF4J。无论我做什么我都会收到此消息:
SLF4J:无法加载类“ org.slf4j.impl.StaticLoggerBinder”。SLF4J:默认为不操作(NOP)记录器实现SLF4J:有关更多详细信息,请参见http://www.slf4j.org/codes.html#StaticLoggerBinder。
我正在尝试登录到控制台,并测试到特定文件夹中的文件后。任何帮助都会很棒。
build.gradle文件:
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'application'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.+'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.apache.poi', name: 'poi', version: '4.+'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.+'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
// compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
implementation 'com.google.firebase:firebase-admin:6.11.0'
}
javafx {
version = '12'
modules = ['javafx.controls', 'javafx.fxml']
}
mainClassName = 'ui.Main'
apply plugin: 'org.openjfx.javafxplugin'
apply plugin: 'idea'
jar {
manifest {
attributes 'Main-Class': mainClassName
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
log4j.properties文件(在src / main / resources /中:]
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
添加//https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14编译组:“ org.slf4j”,名称:“ slf4j-jdk14”,版本:“ 1.7.5”
作为依赖项并尝试一下。
由于您正在将log4j.properties文件与SLf4J一起使用,因此必须使用log4j绑定实现。将以下代码与Slf4j一起使用。
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'
或者如果使用的是更高版本的gradle,则可以使用implementation
代替编译组。
您需要在类路径上使用日志记录框架。如果您不包括其中一个,则SLF4J默认为NOP实现,它将忽略所有内容。
如果要使用log4j
,则需要像这样包含一个绑定:
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'