简体   繁体   English

使用 Junit 测试从 Java AWS S3 客户端禁用调试日志记录

[英]Disable debug logging from Java AWS S3 client with Junit tests

I having a JUnit gradle project that uses the Java AWS s3 client.我有一个使用 Java AWS s3 客户端的 JUnit gradle 项目。

compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.707'
compile group: 'com.amazonaws', name: 'aws-java-sdk-sts', version: '1.11.707'

Since adding this client I am getting tons of log message from org.apache.http classes.自从添加这个客户端后,我从 org.apache.http 类中收到了大量的日志消息。 I cannot figure out how to disable them.我不知道如何禁用它们。

My tests use logback.我的测试使用 logback。 Here is my config:这是我的配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <root level="error">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="STDOUT"/>
    </root>


    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="guru.springframework.controllers" level="WARN" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </logger>
    <logger name="guru.springframework.helpers" level="WARN" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </logger>

    <logger name="com.jayway.jsonpath" level="INFO"/>
    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />

    <logger name="org.apache.zookeeper" level="OFF"/>
    <logger name="org.apache.kafka" level="OFF"/>
    <logger name="ch.qos.logback" level="OFF"/>

    <logger name="org.apache" level="ERROR" />
    <logger name="httpclient" level="ERROR" />

 </configuration>

There are a variety of posts around that suggest ways to solve this, none of which have worked for me.有各种各样的帖子建议解决这个问题的方法,但没有一个对我有用。 Here is an example of one:这是一个例子:

Turn Off Apache Common Logging 关闭 Apache 公共日志记录

With a Junit test I have no main() and I don't know if there is a similar place to put something like:对于 Junit 测试,我没有 main() 并且我不知道是否有类似的地方可以放置类似的东西:

 System.setProperty("org.apache.commons.logging.Log",
                         "org.apache.commons.logging.impl.NoOpLog");

Here is another idea that doesn't work for me:这是另一个对我不起作用的想法:

Disable HttpClient logging 禁用 HttpClient 日志记录

Having these lines in my logback config doesn't see to do anything:在我的 logback 配置中有这些行看不到做任何事情:

    <logger name="org.apache" level="ERROR" />
    <logger name="httpclient" level="ERROR" />

My issue was the fact that I only had a我的问题是我只有一个

main/resources/logback-spring.xml

What I needed was a:我需要的是:

test/resources/logback-test.xml

I am assuming that I needed this because one of my dependencies has a logback-test.xml that was being used instead of my main/resources/logback-spring.xml.我假设我需要这个,因为我的一个依赖项有一个 logback-test.xml,它被用来代替我的 main/resources/logback-spring.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM