[英]How to enable Spring Cloud Contract Wiremock server logging?
As per official document How to Debug , I need to add following to the property file to enable logging根据官方文档How to Debug ,我需要在属性文件中添加以下内容以启用日志记录
logging.level.org.apache.http.wire=DEBUG
logging.level.com.github.tomakehurst.wiremock=DEBUG
But, I don't see any logs visible on the console when request sent to wiremock server.但是,当请求发送到 wiremock 服务器时,我在控制台上看不到任何日志。 I'm getting
500 Internal Server Error
only specific platform.我仅在特定平台上收到
500 Internal Server Error
。 So, to troubleshoot I'm trying to intercept activity when request reached to wiremock server.因此,为了解决问题,我试图在请求到达 wiremock 服务器时拦截活动。
In my pom file在我的 pom 文件中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
I also tried adding logback-test.xml
file with following content.我还尝试添加具有以下内容
logback-test.xml
文件。 But, this is not logging anything as well.但是,这也没有记录任何内容。
<logger name="com.github.tomakehurst.wiremock" level="DEBUG"/>
<logger name="wiremock.org" level="DEBUG"/>
<logger name="WireMock" level="DEBUG"/>
<logger name="/" level="DEBUG"/>
My test class我的测试 class
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
classes = MyApplication.class)
@AutoConfigureMockMvc
@TestPropertySource(
locations = "/application-integration-test.properties"
)
@AutoConfigureWireMock(port = 0)
@AutoConfigureWebTestClient(timeout = "100000")
public class MyApplicationTest {
private WebTestClient client;
@LocalServerPort
private int port;
@Before
public void setUp() throws Exception {
client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();
}
/// Test code
}
Anyone suggest what am missing?有人建议缺少什么吗?
If you are using WireMock via Spring annotation @AutoConfigureWireMock
, best way to see WireMock (verbose) logs in test console output should be to add this bean in your test class:如果您通过 Spring 注释
@AutoConfigureWireMock
使用 WireMock,在测试控制台 output 中查看 WireMock(详细)日志的最佳方法应该是在您的测试 class 中添加此 bean:
@TestConfiguration
static class WireMockTestConfiguration {
@Bean
WireMockConfigurationCustomizer optionsCustomizer() {
return config -> config.notifier(new ConsoleNotifier(true));
}
}
You may use @Import
to add WireMockTestConfiguration
to Spring context.您可以使用
@Import
将WireMockTestConfiguration
添加到 Spring 上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.