gpt4 book ai didi

hadoop - Gradle 用 logback 替换传递依赖 log4j

转载 作者:可可西里 更新时间:2023-11-01 14:57:50 26 4
gpt4 key购买 nike

是否可以用 logback 替换传递依赖中的 log4j?这是我的 gradle 依赖项(https://github.com/geoHeil/lab04/blob/master/build.gradle):

dependencies {
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.1'
compile group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.1'
compile group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-core', version: '2.7.1'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.13'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.3'
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'log4j') {
//prefer 'log4j-over-slf4j' over 'log4j', with fixed version:
details.useTarget "ch.qos.logback:logback-classic:1.1.3"
}
}

我的案例:

  • 我是 Gradle 新手
  • 从事 Hadoop 项目
  • 想要使用当前的记录器,例如登录

现在它似乎不起作用,即使 log4j 应该被替换。警告仍然存在:

log4j:WARN No appenders could be found for logger 
(org.apache.hadoop.util.Shell).
log4j:WARN Please initialize the log4j system properly.

最佳答案

我不确定这是最佳答案还是“正确”答案。但至少 WARN 消息已经消失了:

dependencies {
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.1'
compile group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.1'
compile group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-core', version: '2.7.1'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.13'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.13'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile 'ch.qos.logback:logback-classic:1.1.3'
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'slf4j-log4j12') {
//prefer 'log4j-over-slf4j' over 'log4j', with fixed version:
details.useTarget "ch.qos.logback:logback-classic:1.1.3"
}
}
}

关于hadoop - Gradle 用 logback 替换传递依赖 log4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34024891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com