代码之家  ›  专栏  ›  技术社区  ›  Andy Dingfelder

你如何为一个带模块的毕业生项目设置log4j?

  •  0
  • Andy Dingfelder  · 技术社区  · 6 年前

    你如何为一个带模块的毕业生项目设置log4j?

    project root
    build.gradle
    gradle.properties
    settings.gradle
    // this root project does:
    // include CommonModule
    // includeBuild <all composite modules within module folder>
    
    ---CommonModule
    ------build.gradle
    ------gradle.properties
    ------settings.gradle
    ------src/main/groovy/...<common-code>
    ------src/main/resources/log4j2.xml
    
    Modules
    ---OtherModule-1 
    // this is a gradle composite module
    // it also includes the common module 
    ------build.gradle
    ------gradle.properties
    ------settings.gradle
    ------src/main/groovy/...module1-code
    ------src/main/resources/log4j2.xml
    ---OtherModule-2 
    // this is a gradle composite module
    // it also includes the common module 
    ------build.gradle
    ------gradle.properties
    ------settings.gradle
    ------src/main/groovy/...module2-code
    ------src/main/resources/log4j2.xml
    

    如上所示,我们有一个公共梯度模块和一个包含模块相关组合模块的模块文件夹,每个模块都依赖于包含的公共模块 (核心通用代码是通用的,每个复合模块都包含扩展通用代码的代码

    我的问题很简单:

    • 在哪里配置log4j模块?
    • 或者每个复合模块都需要有自己的log4j xml?
    1 回复  |  直到 6 年前
        1
  •  0
  •   Andy Dingfelder    6 年前

    我在毕业生论坛上问了同样的问题 https://discuss.gradle.org/t/how-do-you-set-up-log4j-for-a-gradle-project-with-modules/28262 得到了答案-

    • 公共模块不包括log4j配置单个库
    • 模块不包括log4j配置,也不包括顶级应用程序
    • 类路径(我设置了一个src/[configuration]/config目录 为了这个)
    • build或from a JavaExec in the Gradle build)指定 log4j配置是从加载的,这样您就不会意外地 被类路径上的其他配置毒害
    • 您可以通过在gradle属性文件中提供-D标志来定义xml位置,例如-Dlog4j.configurationFile=
    • 另外-Dlog4j.debug可能有助于跟踪问题