简体   繁体   English

如何启用 Spring Cloud Contract Wiremock 服务器日志记录?

[英]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.您可以使用@ImportWireMockTestConfiguration添加到 Spring 上下文。

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

相关问题 如何让 Spring Cloud Contract 在每次测试之前或之后重置 WireMock - How to make Spring Cloud Contract reset WireMock before or after each test 如何在 Spring Cloud Contract 存根上执行 WireMock.verify() 操作? - How can I do a WireMock.verify() operation on a Spring Cloud Contract stub? spring-cloud-contract-wiremock | 自动注册存根与以编程方式注册 - spring-cloud-contract-wiremock | Registering Stubs Automatically vs Programmatically 无法使用 Spring 云合约 Wiremock,无法加载 ApplicationContext - Can not use Spring Cloud Contract Wiremock, Failed to load ApplicationContext 如何在 spring-cloud-gateway 合约测试中从 spring-cloud-contract 中设置带有 StubRunner 端口的 url - How to set urls with port of StubRunner from spring-cloud-contract in spring-cloud-gateway contract tests 如何在Spring Junit测试中启用日志记录? - How to enable logging in Spring Junit test? 如何在 spring 启动 jar 中启用文件日志记录 - how to enable file logging in spring boot jar 如何在Jetty服务器中启用电汇记录 - How to enable wire logging in Jetty Server 春季云合同-假客户 - spring cloud contract - Feign Clients Spring Cloud Contract - 是消费者驱动的吗? - Spring Cloud Contract - is it Consumer Driven?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM