所以我想为JUnit测试禁用日志记录。
最简单的方法是将绑定从slf4j-simple
切换到slf4j-nop
。
但是我该怎么做?
我尝试了exclude
:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "org.slf4j:slf4j-simple:1.6.1"
testImplementation("org.slf4j:slf4j-nop:1.6.1"){
exclude(group:'org.slf4j', module:'slf4j-simple')
}
implementation 'io.github.microutils:kotlin-logging:1.6.10'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
但这仍然会导致
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/user1291/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-nop/1.6.1/70249094d4e5653b6bdfea46f3a1a4165c1e1993/slf4j-nop-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/user1291/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.6.1/58e59bfb3e247097b8122243b3bfe0049c8cfae8/slf4j-simple-1.6.1.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.slf4j.helpers.NOPLoggerFactory]
还尝试了configurations
:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "org.slf4j:slf4j-simple:1.6.1"
testImplementation "org.slf4j:slf4j-nop:1.6.1"
implementation 'io.github.microutils:kotlin-logging:1.6.10'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
configurations{
testImplementation.exclude(group:'org.slf4j',module:'slf4j-simple')
}
没什么区别。
答案 0 :(得分:1)
尝试一下:
window
答案 1 :(得分:0)
我会走另外一条路。 SLF4J的简单记录器将在您的类路径中查找.header {
background-color: transparent;
padding: 50px;
position: fixed;
top: 0;
width: 100%;
z-index: 97;
}
@media screen and (max-width: 767px) {
.header {
padding: 20px;
}
}
.header.overlay-header {
position: relative;
}
.header .primary-header {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
margin-bottom: 15px;
}
.header .secondary-header {
margin: 0 auto;
text-align: center;
}
.header .header-center {
text-align: center;
}
。如果将其放在simplelogger.properties
中,则测试代码应在类路径中找到它,并且可以使用它来关闭SLF4J的输出。
src/test/resources
您可以看到配置属性的完整列表,以及简单记录器on its javadoc page的详细说明。