简体   繁体   English

WireMock 无法将 log4j 级别设置为 INFO 而不是 DEBUG

[英]WireMock unable to set log4j level to INFO instead of DEBUG

I'm running JUnit testcases with WireMock.我正在使用 WireMock 运行 JUnit 测试用例。 Embedded Jetty Server is configured as follows.嵌入式 Jetty Server 配置如下。

@Before
public void setup() {


    final ResponseTemplateTransformer theTemplateTransformer =
            new ResponseTemplateTransformer(false);

    templateTransformerName = theTemplateTransformer.getName();

    mWireMockServer = new WireMockServer(
            WireMockConfiguration
                    .options()
                    .notifier(new ConsoleNotifier(false))
                    .extensions(theTemplateTransformer));
    mWireMockServer.start();


}

The output of the setup() method alone is very verbose, about 200 lines long.setup()方法的输出就非常冗长,大约有 200 行。 It starts like this:它是这样开始的:

> Task :processResources
> Task :classes
> Task :compileTestJava
> Task :processTestResources
> Task :testClasses
> Task :test
log4j: Threshold ="null".
log4j: Level value for root is  [DEBUG].
log4j: root level set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Setting property [immediateFlush] to [true].
log4j: Setting property [threshold] to [ALL].
log4j: Setting property [target] to [System.out].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss.SSS} [%5p] [%t] [%c{1}] [%F:%L] [%X{uuid}] - %m%n].
log4j: Adding appender named [ConsoleAppender] to category [root].
2019-12-09 11:28:06.813 [DEBUG] [Test worker] [log] [Log.java:159] [] - Logging to org.slf4j.impl.Log4jLoggerAdapter(wiremock.org.eclipse.jetty.util.log) via wiremock.org.eclipse.jetty.util.log.Slf4jLog
2019-12-09 11:28:06.820 [ INFO] [Test worker] [log] [Log.java:169] [] - Logging initialized @1394ms to wiremock.org.eclipse.jetty.util.log.Slf4jLog
2019-12-09 11:28:06.841 [DEBUG] [Test worker] [ContainerLifeCycle] [ContainerLifeCycle.java:412] [] - Server@2173e69b{STOPPED}[9.4.20.v20190813] added {QueuedThreadPool[qtp547179568]@209d4c30{STOPPED,8<=0<=14,i=0,r=-1,q=0}[NO_TRY],AUTO}
2019-12-09 11:28:06.856 [DEBUG] [Test worker] [ContainerLifeCycle] [ContainerLifeCycle.java:412] [] - HttpConnectionFactory@4f25c098[HTTP/1.1] added {HttpConfiguration@613f727b{32768/8192,8192/8192,https://:0,[]},POJO}
2019-12-09 11:28:06.864 [DEBUG] [Test worker] [ContainerLifeCycle] [ContainerLifeCycle.java:412] [] - NetworkTrafficServerConnector@5a238421{null,[]}{0.0.0.0:0} added {Server@2173e69b{STOPPED}[9.4.20.v20190813],UNMANAGED}
2019-12-09 11:28:06.865 [DEBUG] [Test worker] [ContainerLifeCycle] [ContainerLifeCycle.java:412] [] - NetworkTrafficServerConnector@5a238421{null,[]}{0.0.0.0:0} added {QueuedThreadPool[qtp547179568]@209d4c30{STOPPED,8<=0<=14,i=0,r=-1,q=0}[NO_TRY],AUTO}
2019-12-09 11:28:06.865 [DEBUG] [Test worker] [ContainerLifeCycle] [ContainerLifeCycle.java:412] [] - NetworkTrafficServerConnector@5a238421{null,[]}{0.0.0.0:0} added {ScheduledExecutorScheduler@5839ea4{STOPPED},AUTO}
2019-12-09 11:28:06.866 [DEBUG] [Test worker] [ContainerLifeCycle] [ContainerLifeCycle.java:412] [] - NetworkTrafficServerConnector@5a238421{null,[]}{0.0.0.0:0} added {wiremock.org.eclipse.jetty.io.ArrayByteBufferPool@f73022f,POJO}

I do not want to print out DEBUG logs, just INFO level stuff .我不想打印 DEBUG 日志,只是 INFO 级别的东西 I tried to do this by changing the WireMock Configuration as follows.我尝试通过如下更改 WireMock 配置来做到这一点。 What I'm doing is described in the official documentation , section Notification (logging) , so feel free to have a look.我正在做的事情在官方文档的Notification (logging)部分中有描述,所以请随意查看。

.notifier(new ConsoleNotifier(false)) //attribute verbose is set to false

Also tried to solve this by adding a log4j.properties file under src/test/resources/还试图通过在 src/test/resources/ 下添加一个 log4j.properties 文件来解决这个问题

log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

log4j.logger.org.apache.http.wire=INFO

Can someone help me please?有人能帮助我吗?

This worked in my case (Spring, Logback) - src/test/resources/logback-test.xml这在我的情况下有效(Spring,Logback) - src/test/resources/logback-test.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />

    <!-- Decrease amount of logs from Jetty started by WireMock -->
    <logger name="org.eclipse.jetty" level="info"/>
    <logger name="org.eclipse.jetty.server.handler.ContextHandler" level="warn"/>
</configuration>

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

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