我在集成测试套件中使用commons-httpclient 3.1.HttpClient的默认日志记录非常嘈杂,我似乎无法将其关闭.我试过按照这里的说明,但没有一个有任何区别.
大多数情况下,我只需要关闭org.apache.http.wire记录器.问题的一部分是我不知道HttpClient尝试使用什么类型的记录器,大多数问题是我之前从未使用过这个库.我尝试创建一个log4j.properties文件并将其放在我的test/resources文件夹中,修改jre/lib中的master logging.properties文件,并按照日志页面上的指定将各种日志记录选项发送到Maven ,而不是它们都没有有所作为.
任何帮助表示赞赏......这让我疯狂.
更新:更正:看来有问题的输出实际上是通过jwebunit使用HttpClient而不是我自己的.无论哪种方式,这都是不可取的.
更新:感谢迄今为止的尝试.我已经尝试了下面提出的所有建议,但仍然没有运气.我在src/test/resources文件夹中有一个文件commons-logging.properties,其中包含以下内容
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory
log4j.configuration=log4j.properties
Run Code Online (Sandbox Code Playgroud)
以及具有以下内容的同一文件夹中的文件log4j.properties
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
#This is the line that should make httpclient shut up
log4j.logger.org.apache.http=ERROR
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的测试时,我仍然得到一堆像这样的输出:
21:57:41.413 [main] DEBUG org.apache.http.wire - << " [\r][\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << " [\r][\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << " </ul>[\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << " [\n]"
21:57:41.424 [main] DEBUG …Run Code Online (Sandbox Code Playgroud) 我的一个maven模块在运行测试时忽略了我的日志记录级别.
在src/test/resources中我有application.properties:
app.name=bbsng-import-backend
app.description=Import Backend Module for Application
spring.profiles.active=test
# LOGGING
logging.level.root=error
logging.level.org.springframework.core =fatal
logging.level.org.springframework.beans=fatal
logging.level.org.springframework.context=fatal
logging.level.org.springframework.transaction=error
logging.level.org.springframework.test=error
logging.level.org.springframework.web=error
logging.level.org.hibernate=ERROR
Run Code Online (Sandbox Code Playgroud)
我也尝试过application-test.properties.
我的应用程序记录很多,特别是在加载上下文时.我尝试了logback.xml,logback-test.xml和logback-spring.xml,但没有任何帮助.
我的pom:
<parent>
<groupId>at.company.bbsng</groupId>
<artifactId>bbsng-import</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>bbsng-import-backend</artifactId>
<name>bbsng-import-backend</name>
<properties>
<start-class>at.company.bbsng.dataimport.ApplicationImportBackend</start-class>
</properties>
<dependencies>
<!-- APPLICATION ... -->
<dependency>
<groupId>at.company.bbsng</groupId>
<artifactId>bbsng-app-domain</artifactId>
<scope>test</scope>
</dependency>
<!-- SPRING ... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>test</scope>
</dependency>
<!-- JAVAX ... -->
...
<!-- COMMONS ... -->
...
<!-- LOMBOK ... -->
...
<!-- DB -->
... …Run Code Online (Sandbox Code Playgroud) 如何配置Logback以抑制其到控制台的所有输出(标准输出)?特别是,我希望抑制(或重定向)Logback自己的日志消息,如下所示:
16:50:25,814 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:50:25,814 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml]
16:50:25,816 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
16:50:25,816 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml]
16:50:25,816 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml]
16:50:25,923 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
16:50:25,924 |-INFO in ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter@1a15291 - Will scan for changes in file [/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml] every 60 seconds.
Run Code Online (Sandbox Code Playgroud)
我需要禁用所有日志记录到标准输出,因为我们的生产环境不允许应用程序将任何消息打印到标准输出.
注意我正在使用Logback …