Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No logs from WireMock #1916

Closed
bartoliniii opened this issue Jun 28, 2023 · 5 comments
Closed

No logs from WireMock #1916

bartoliniii opened this issue Jun 28, 2023 · 5 comments
Labels
Milestone

Comments

@bartoliniii
Copy link

bartoliniii commented Jun 28, 2023

Hello!
I'm using the latest version of Spring Cloud Contract (4.0.3) with Spring Boot 3.1.0 with slf4j-api 2.0.7 with log4j 2.19.0.
I have a very simple stub runner run by annotation (@AutoConfigureStubRunner), with embedded wiremock run on random port and it works pretty well, but I can't see any logs from WireMock.

According to this article is should work out of the box, but it doesn't in my case.

I debugged a little and I found that the reason is that wiremock-jre8-standalone uses its own copy of slf4j classes prefixed with wiremock package (e.g. wiremock.org.slf4j.Logger) so my log configuration can't work with it and finally NOPLogger from wiremock.org.slf4j package is used.

I didn't find any way to make logger working. I even tried to replace wiremock-jre8-standalone and use a standard wiremock-jre8, but it is not possible - some classes e.g. HandlebarsTemplateProcessor uses repacked dependencies from standalone version of wiremock.

Did I miss something?
Is there any way to make it working?

@copbint
Copy link

copbint commented Jul 25, 2023

I have come across this issue too, and can't find solution.

@marcingrzejszczak
Copy link
Contributor

Do you have a small project that replicates this issue?

@tgeens
Copy link

tgeens commented Sep 5, 2023

@SpringBootTest
@AutoConfigureWireMock(port = 0)
public class AutoConfigureWireMockApplicationTests {

    @Autowired
    WireMockServer wireMockServer;

    @Test
    public void testLogging() {
        wireMockServer.stubFor(get(urlEqualTo("/test"))
                .willReturn(ok("Hello World!")));

        var result = WebClient.create()
                .get().uri("http://localhost:{port}/test", wireMockServer.port())
                .exchangeToMono(response -> response.bodyToMono(String.class))
                .block();

        assertThat(result).isEqualTo("Hello World!");
    }
}

Trying this (in my webflux project) gives 0 wiremock logging.

I tried setting logging.level.WireMock=DEBUG etc, but that gives the same result.

@tgeens
Copy link

tgeens commented Sep 5, 2023

As a workaround, I switched to the ConsoleNotifier and this works as expected:

    @Bean
    WireMockConfigurationCustomizer optionsCustomizer() {
        return config -> config.notifier(new ConsoleNotifier(true));
    }

That reduces the logging-problem to a slf4j/logback config issue? 🤔

@adamsmith118
Copy link

adamsmith118 commented Sep 5, 2023

That reduces the logging-problem to a slf4j/logback config issue? 🤔

Presumably it's defaulting NOPLogger, which wouldn't write anything...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Status: No status
Development

No branches or pull requests

6 participants