21

I'm using Wiremock for my tests in a Spring Boot app. I can't seem to get the logging to not output all debug logs, which makes my test runs very verbose.

I see it use SLF4J on startup:

DEBUG wiremock.org.eclipse.jetty.util.log - Logging to Logger[wiremock.org.eclipse.jetty.util.log] via wiremock.org.eclipse.jetty.util.log.Slf4jLog

But trying to configure it in my application.properties via,

logging.level.wiremock.org.eclipse=WARN

Has no effect, I've also setup

logging.level.com.github.tomakehurst.wiremock=WARN

But again, no effect. Since I'm using spring-boot-starter-web which uses spring-boot-starter-logging, which if I understand correctly uses Logback, I've also tried configuring this in logback-spring.xml,

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="wiremock.org.eclipse" level="INFO"/>
</configuration>

Again, nothing I do stops Wiremock from logging debug level. What am I missing?

James McMahon
  • 48,506
  • 64
  • 207
  • 283

4 Answers4

24

Ok Ive just had this problem and finally solved it. There are 3 different loggers you need to configure

  • the eclipse logger at wiremock.org.eclipse
  • the wiremock notifier at WireMock
  • the serverlet logger at "/" or what ever your logger is located at.
  • the wiremock code logging at com.github.tomakehurst.wiremock

Ive found that the bootstrap.yml does not affect these loggers so you need to put them in your logback-test.xml in your /src/test/resources folder

with the following entries.

<!-- Turning down the wiremock logging -->
<logger name="com.github.tomakehurst.wiremock" level="WARN"/>
<logger name="wiremock.org" level="ERROR"/>
<logger name="WireMock" level="WARN"/>
<!-- wiremock has per endpoint servlet logging -->
<logger name="/" level="WARN"/>
vkrams
  • 7,267
  • 17
  • 79
  • 129
Kevlar
  • 376
  • 3
  • 5
0

A quick fix is to change logging.level.root; INFO will make WireMock to be verbose enough to check stub matching while WARN will prevent it.

This has its side effect, of course; this affects all logging; but is dirty and quick.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
0

If you want to achieve this programmatically and you are using SLF4J with Logback (the default in Spring Boot 2.2), just do this:

((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("wiremock").setLevel(Level.OFF);
((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("WireMock").setLevel(Level.OFF);

(Using WireMock 2.25)

dav.garcia
  • 546
  • 8
  • 13
0

As you are using Spring Boot, you could simply add this configuration: https://stackoverflow.com/a/75626043/3263041

Florian Lopes
  • 1,093
  • 1
  • 13
  • 20