如何使用 Gradle 在 IntelliJ 中设置 SLF4J
How to set SLF4J in IntelliJ with Gradle
我很难在 IntelliJ 中使用 Gradle 配置 SLF4J。无论我做什么,我都会收到此消息:
SLF4J:无法加载 class "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
Compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
作为依赖并试一试。
由于您将 log4j.properties 文件与 SLf4J 一起使用,因此您必须使用 log4j 绑定实现。将以下代码与 Slf4j 一起使用。
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'
或者如果您使用更高版本的 gradle,您可以使用 implementation
代替编译组。
implementation 'org.slf4j:slf4j-log4j1:1.7.29'
您的类路径中需要一个日志记录框架。 SLF4J 是一个支持多种实现(logback、log4j 等)的日志外观。但是,如果您不包含特定的后端,SLF4J 默认为 NOP 实现,它会忽略所有内容。 :)
如果你想使用 log4j
,你需要像这样包含一个绑定:
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'
有关详细信息,请参阅 http://www.slf4j.org/manual.html#swapping
PythonLearner 的响应是正确的,但是使用实现你需要这样:
implementation 'org.slf4j:slf4j-log4j12:1.7.29'
我很难在 IntelliJ 中使用 Gradle 配置 SLF4J。无论我做什么,我都会收到此消息:
SLF4J:无法加载 class "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
Compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
作为依赖并试一试。
由于您将 log4j.properties 文件与 SLf4J 一起使用,因此您必须使用 log4j 绑定实现。将以下代码与 Slf4j 一起使用。
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'
或者如果您使用更高版本的 gradle,您可以使用 implementation
代替编译组。
implementation 'org.slf4j:slf4j-log4j1:1.7.29'
您的类路径中需要一个日志记录框架。 SLF4J 是一个支持多种实现(logback、log4j 等)的日志外观。但是,如果您不包含特定的后端,SLF4J 默认为 NOP 实现,它会忽略所有内容。 :)
如果你想使用 log4j
,你需要像这样包含一个绑定:
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'
有关详细信息,请参阅 http://www.slf4j.org/manual.html#swapping
PythonLearner 的响应是正确的,但是使用实现你需要这样:
implementation 'org.slf4j:slf4j-log4j12:1.7.29'