2016-04-15 3 views
0

私は、gradleをビルドツールとして使用するプロジェクトでログバックを設定しようとしています。これは、ビルドファイルgradleでlogback classicを使用しているときにログバック設定を読み込めません

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のための設定が含まれているlogback.groovyファイルです

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] 

それを解決するために私はこのstack overflow questionの答えに続き、この余分なコードを私のビルドファイルに追加しました

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

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

答えて

0

Gradleには、実際に置き換えたり追加したりできない独自のログフレームワークが付属しています。 GradleプラグインでGradleロガーを使用することをお勧めします。

関連する問題