1

gradle をビルド ツールとして使用するプロジェクトで logback を設定しようとしています。これはビルドファイルです

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'maven'


sourceCompatibility = 1.8

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compile gradleApi()
    compile localGroovy()
    compile 'org.liquibase:liquibase-core:3.0.1'
    compile 'org.jdbi:jdbi:2.71'
    compile 'org.postgresql:postgresql:9.4.1208.jre7'
    compile 'ch.qos.logback:logback-classic:1.1.7'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile 'org.powermock:powermock-module-junit4:1.6.1'
    testCompile 'org.powermock:powermock-api-mockito:1.6.1'
}

そして、これはlogback.groovylogbackの構成を含むファイルです

import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import org.apache.log4j.FileAppender

root(DEBUG, ["CONSOLE", "FILE"])

appender("FILE", FileAppender) {
    file = "testFile.log"
    append = true
    encoder(PatternLayoutEncoder) {
        pattern = "%level %logger - %msg %n"
    }
}

何かをログに記録しようとすると、この SLF4J 警告が表示されました

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.12/libexec/lib/gradle-core-2.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/shishir/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.7/9865cf6994f9ff13fce0bf93f2054ef6c65bb462/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.gradle.logging.internal.slf4j.OutputEventListenerBackedLoggerContext]

それを解決するために、このスタックオーバーフローの質問への回答に従い、この余分なコードをビルドファイルに追加しました

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    if (details.requested.name == 'logback-classic') {
        details.useTarget 'org.slf4j:slf4j-api:1.7.5'
    }
}

これにより SLF4J 警告の問題は解決されましたが、ログが機能しません。追加したロギング ステートメントは、 で指定されたパターンで STDOUT に出力されませんlogback.groovy。ログもファイルに追加されていません。誰かが私を正しい方向に向けることができますか?

4

1 に答える 1