Log4j2用のGrails3の構成

fcnorman

Grails3とのログバインディングとしてLog4j2を使用したいと思います。

私がこれまでに理解できることから。さまざまなロガーを使用する多くの従属依存関係があるため、SLF4JAPIを使用する必要があります。次に、grails / groovy / springがSLF4JAPIをLogbackバインディングにリダイレクトする代わりに、それぞれをLog4j2バインディングにリダイレクトする必要があります。

grails 3はLogbackバインディングを使用するため、build.gradleの各依存関係を調べ、Logbackバインディングを除外し、Log4j2バインディングを含めることを計画しています。これは機能しますか?更新:はい

Log4j2APIをSLF4jAPIにブリッジする必要もありますか?そのためにどのような依存関係が必要ですか?更新:以下を参照してください。

最後に、grails 3 logback.groovy構成を破棄し、log4j2構成の1つをsrc / main / resourcesに配置する必要があると想定します。更新:はい

これがわかったら更新を投稿しますが、誰かが以前にこれを行ったことがあるに違いありません。

更新2016-03-18:

これは非常に簡単であることが判明しました。grails 3プロジェクトで「./gradlew依存関係」を実行して、Logbackバインディング/実装でどの依存関係がプルされているかを確認しました(グループ:「ch.qos.logback」、モジュール:「logback-classic」)

まず、「grailscreate-apptestit」コマンドを介して生成されたデフォルトのbuild.gradleを次に示します。

buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
        classpath "org.grails.plugins:hibernate4:5.0.2"
    }
}

version "0.1"
group "testit"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"asset-pipeline"

ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion
}

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate4"
    compile "org.hibernate:hibernate-ehcache"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web:3.1.4"
    runtime "org.grails.plugins:asset-pipeline"
    runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

task wrapper(type: Wrapper) {
    gradleVersion = gradleWrapperVersion
}

assets {
    minifyJs = true
    minifyCss = true
}

依存関係レポートは、それらが2つの依存関係によって引き込まれていることを示しました。

    compile "org.springframework.boot:spring-boot-starter-logging"

そして

    compile "org.springframework.boot:spring-boot-starter-actuator"

したがって、build.gradleの依存関係セクションにいくつかの変更を加えるだけで済みました。

dependencies {
    // commented out the original way using Logback    
    //compile "org.springframework.boot:spring-boot-starter-logging"

    // added the new way using Log4j2, yes, spring makes it easy
    compile "org.springframework.boot:spring-boot-starter-log4j2"

    // changed spring-boot-autoconfigure so that it would not
    // pull in the logback binding/implementation
    compile ('org.springframework.boot:spring-boot-autoconfigure') {
       exclude group: 'ch.qos.logback', module: 'logback-classic'
    }

    // and finally, added the log4j2 binding/implementation
    compile "org.apache.logging.log4j:log4j-api:2.5"
    compile "org.apache.logging.log4j:log4j-core:2.5"

    // the rest is unchanged
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate4"
    compile "org.hibernate:hibernate-ehcache"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web:3.1.4"
    runtime "org.grails.plugins:asset-pipeline"
    runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

src / main / resourcesに、log4j2.xmlを追加しました。

グルーヴィーなコードでは、次のものを使用しました。

import org.apache.logging.log4j.Logger
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.ThreadContext

private static final Logger log = LogManager.getLogger(getClass())

log.info('Hello World')

また、頻繁に使用されるクラスのコンストラクターにThreadContextステートメントを配置します。

それだけです。現在、構成の変更時にログメッセージが失われない高速の非同期ロギングを実行しています。

fcnorman

答えとして何かを投稿するのを忘れました。投票できる回答は次のとおりですが、ソリューションに関するすべての情報を上記のコメントに記載します。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Postgresql用のGrails3の構成

分類Dev

Grails3での構成の分割

分類Dev

log4j2 xml 構成タグの dest 属性の例

分類Dev

Syslog-ngおよびLog4j2の構成

分類Dev

Log4j2の初期化後にFileAppenderを構成する

分類Dev

Springでのプロファイル依存のlog4j2構成

分類Dev

SpringBootでの構成に関するLog4j2の問題

分類Dev

単一のlog4j2 xmlファイルを使用したlog4j2およびlog4jの構成

分類Dev

log4j2構成のユーザーJVMパラメーター

分類Dev

Java EEアプリケーションでの外部Log4J2構成

分類Dev

Log4j2:Yaml構成で同じタイプの複数のAppenderを構成する方法

分類Dev

Grails3とSpringSecurityRESTを使用したCORSの構成

分類Dev

Grails3プラグインの構成

分類Dev

log4j2のCustomInjections

分類Dev

SpringBootのLog4j2

分類Dev

Log4j2のLog4jNestedDiagnosticContextFilter

分類Dev

Log4j2のLog4jNestedDiagnosticContextFilter

分類Dev

Log4j2のLog4jNestedDiagnosticContextFilter

分類Dev

実行可能JARを使用する場合のLog4j2構成ファイルの指定

分類Dev

log4j2の「構成ステータス」と「ルートレベル」の違いは何ですか

分類Dev

Log4j2構成での「ステータス」とはどういう意味ですか?

分類Dev

プログラムによるLog4j2構成ファイルの読み込み

分類Dev

log4j2の構成ファイルと組み合わせたカスタムConfigurationFactory

分類Dev

log4j2の構成ファイルと組み合わせたカスタムConfigurationFactory

分類Dev

複数の条件でlog4j2プロパティファイルを構成できません

分類Dev

ファイルサイズが超過した場合のLog4j2自動再構成

分類Dev

YAMLファイルからlog4j2を自動構成する際の問題

分類Dev

Spring ConfigServerルックアップのlog4j2構成ファイルが機能しない

分類Dev

log4j2構成のデバッグメッセージが表示されないようにする

Related 関連記事

  1. 1

    Postgresql用のGrails3の構成

  2. 2

    Grails3での構成の分割

  3. 3

    log4j2 xml 構成タグの dest 属性の例

  4. 4

    Syslog-ngおよびLog4j2の構成

  5. 5

    Log4j2の初期化後にFileAppenderを構成する

  6. 6

    Springでのプロファイル依存のlog4j2構成

  7. 7

    SpringBootでの構成に関するLog4j2の問題

  8. 8

    単一のlog4j2 xmlファイルを使用したlog4j2およびlog4jの構成

  9. 9

    log4j2構成のユーザーJVMパラメーター

  10. 10

    Java EEアプリケーションでの外部Log4J2構成

  11. 11

    Log4j2:Yaml構成で同じタイプの複数のAppenderを構成する方法

  12. 12

    Grails3とSpringSecurityRESTを使用したCORSの構成

  13. 13

    Grails3プラグインの構成

  14. 14

    log4j2のCustomInjections

  15. 15

    SpringBootのLog4j2

  16. 16

    Log4j2のLog4jNestedDiagnosticContextFilter

  17. 17

    Log4j2のLog4jNestedDiagnosticContextFilter

  18. 18

    Log4j2のLog4jNestedDiagnosticContextFilter

  19. 19

    実行可能JARを使用する場合のLog4j2構成ファイルの指定

  20. 20

    log4j2の「構成ステータス」と「ルートレベル」の違いは何ですか

  21. 21

    Log4j2構成での「ステータス」とはどういう意味ですか?

  22. 22

    プログラムによるLog4j2構成ファイルの読み込み

  23. 23

    log4j2の構成ファイルと組み合わせたカスタムConfigurationFactory

  24. 24

    log4j2の構成ファイルと組み合わせたカスタムConfigurationFactory

  25. 25

    複数の条件でlog4j2プロパティファイルを構成できません

  26. 26

    ファイルサイズが超過した場合のLog4j2自動再構成

  27. 27

    YAMLファイルからlog4j2を自動構成する際の問題

  28. 28

    Spring ConfigServerルックアップのlog4j2構成ファイルが機能しない

  29. 29

    log4j2構成のデバッグメッセージが表示されないようにする

ホットタグ

アーカイブ