gpt4 book ai didi

java - 禁用 WireMock 的日志记录

转载 作者:行者123 更新时间:2023-12-05 03:23:03 26 4
gpt4 key购买 nike

我正在使用 @AutoConfigureWireMock(port = 0) 来初始化模拟服务器。

这是用 Kotlin 编写的设置类:

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

@Autowired
lateinit var mockServer: WireMockServer

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

它工作正常,我在运行测试时看到以下登录控制台:

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]

我的问题是,我可以关闭这个日志吗?

原因是我们正在编写一个性能测试,在 header 中传递超长字符串,控制台被该字符串淹没,有时甚至会导致 VM 崩溃。

我做了一些搜索,有人在启动选项中提到了 ConsoleNotifier,但是有了这个 @AutoConfigureWireMock 注释,我不知道在哪里设置通知程序。

最佳答案

感谢 @chrylis 的建议

通过在 /src/test/resources 文件夹下添加 logback-test.xml 解决,内容如下:

<?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>


更新:logback-test.xml

关于java - 禁用 WireMock 的日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72581257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com