我很难在 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
原文由 xblaz3kx 发布,翻译遵循 CC BY-SA 4.0 许可协议
您的类路径上需要一个日志记录框架。 SLF4J 是一个支持多种实现(logback、log4j 等)的日志外观。但是,如果您不包含特定的后端,SLF4J 默认为 NOP 实现,它会忽略所有内容。 :)
如果你想使用
log4j
,你需要像这样包含一个绑定:有关详细信息,请参阅 http://www.slf4j.org/manual.html#swapping