如何使用Gradle在IntelliJ中设置SLF4J [英] How to set SLF4J in IntelliJ with Gradle

查看:73
本文介绍了如何使用Gradle在IntelliJ中设置SLF4J的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难用IntelliJ中的Gradle配置SLF4J.无论我做什么我都会收到此消息:

I'm having a hard time configuring SLF4J with Gradle in IntelliJ. No matter what I do I get this message:

SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".SLF4J:默认为不操作(NOP)记录器实现SLF4J:请参见 http://www.slf4j.org/codes.html#StaticLoggerBinder 了解更多详细信息.

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'm trying to log in to the console and after testing to a file in a specific folder. Any help would be great.

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

推荐答案

您需要在类路径上有一个日志记录框架.SLF4J 是一个支持多种实现(logback、log4j 等)的日志记录门面.但是,如果您不包括特定的后端,则SLF4J默认使用NOP实现,该实现只会忽略所有内容.:)

You need a logging framework on your classpath. SLF4J is a logging facade that supports multiple implementations (logback, log4j etc.). However, if you don't include a specific backend, SLF4J defaults to a NOP implementation that simply ignores everything. :)

如果要使用 log4j ,则需要为其添加一个绑定,如下所示:

If you want to use log4j, you need to include a binding for it like this:

compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.29'

有关更多信息,请参见 http://www.slf4j.org/manual.html#交换

For more information, see http://www.slf4j.org/manual.html#swapping

这篇关于如何使用Gradle在IntelliJ中设置SLF4J的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆