Deqing
Deqing

Reputation: 14632

Disable logging of WireMock

I'm using @AutoConfigureWireMock(port = 0) to init mock server.

This is the setup class written in Kotlin:

@AutoConfigureWireMock(port = 0)
@SpringBootTest(
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
)
class MockServerBase {

    @Autowired
    lateinit var mockServer: WireMockServer

    @BeforeEach
    fun setUp() {
        mockServer.start()
    }

It's working fine, and I'm seeing following log in console when running my test:

2022-06-11 11:58:14.639  INFO [...,,] 97733 --- [qtp630910066-62] WireMock                                 : Request received:
127.0.0.1 - GET /api/v1/.../objects/b4a67951-4408-424f-916b-66852b012160

Authorization: [Bearer eyJraWQiOiJtaWNyb3NcL29zLXRlc3RlclwvMTY1Mjg1ODYyMiIsImFsZyI6IlJTMjU2In0.eyJhdWQiOiJ0ZHAtb3MiLCJuYmYiOjE2NTQ5MTI2OTQsImlzcyI6Im1pY3Jvc1wvb3MtdGVzdGVyIiwiZXhwIjoxNjU0OTEyNzU0LCJpYXQiOjE2NTQ5MTI2OTQsImp0aSI6ImU5MGNlMGI0LTlmMjMtNDJlNS1iMDc4LWU4MGE0ZWI5MzFjOCJ9.U35a8zPH8-HZeWwSKaFq2KDebLkdWz99YCxcs9qDBYcPCRn_s_BhKJLgu8OCq3s4MAC0VmGZS6JqRzvUa-qIqfoA3DT6LSoDoVRwEZycnlL3OP6PJ6nVz1u-zkaNHfz8mBQ-3xuPmDKRddBArcvMfb7LuM3n-Tv6d1hb87QnDHqWqyl9S976jd4QKd21ymm30LziW1QeJXAINcq6YRvJfTZ7AhdorwYy0AwhGE-LD8xqYjUJwuy-WQaHsuZ8oClGIm3mUy2su5yIVHwQEldI2Gxv9gefF6eH__e4bdWWPwaDtkN2_KKIEBJaVGk53292EuRzQixO5UCe3rIuP1X96A]
Accept: [application/json]
X-B3-SpanId: [b91171b9168b6d9c]
User-Agent: [ReactorNetty/1.0.17]
X-B3-Sampled: [1]
Host: [localhost:10441]
X-B3-TraceId: [b91171b9168b6d9c]
x-partition-id: [v1-test]



Matched response definition:
{
  "status" : 200,
  "body" : "{\"bucketKey\":\"....\",\"objectId\":\"b4a67951-4408-424f-916b-66852b012160\",\"partitionId\":\"v1-test\",\"currentVersion\":\"1654912692121\",\"checksum\":\"OJEcxfNhApqHyPfrShDS\",\"s3Etag\":\"0Y5AwxkypfgbZ9mEyUa7og==-4\",\"size\":20971520,\"creationInfo\":{\"by\":\"o0m6CQM0Db\",\"at\":1654912692121},\"updateInfo\":null}",
  "headers" : {
    "Content-Type" : "application/json"
  }
}

Response:
HTTP/1.1 200
Content-Type: [application/json]
Matched-Stub-Id: [e8be9cdb-0138-4490-a65f-07562812fedc]

My question is, can I turn this log off?

The reason is we are writing a performance test that passing a super long string in the header, the console is flooded with that string and sometimes even crashes VM.

I did some searching and someone mentioned ConsoleNotifier in startup options, but with this @AutoConfigureWireMock annotation I don't know where to set the notifier.

Upvotes: 5

Views: 3727

Answers (2)

Florian Lopes
Florian Lopes

Reputation: 1289

Using Spring Boot, you can simply add this configuration to application-test.yml file:

logging:
  level:
    WireMock: WARN

Upvotes: 2

Deqing
Deqing

Reputation: 14632

Thanks suggestion from @chrylis

Solved by adding logback-test.xml under /src/test/resources folder with following content:

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

    <!-- Turning down the wiremock logging -->
    <logger name="com.github.tomakehurst.wiremock" level="WARN"/>
    <logger name="wiremock.org" level="WARN"/>
    <logger name="WireMock" level="WARN"/>

    <!-- wiremock has per endpoint servlet logging -->
    <logger name="/" level="WARN"/>
</configuration>

   

updated: logback-test.xml

Upvotes: 4

Related Questions