Is there a way to set Logbook log level above TRACE?

2.6k Views Asked by At

I would like the Logbook logger to log at level INFO instead of TRACE. The documentation states:

The logbook logger must be configured to trace level in order to log the requests and responses

I understand that perhaps this is a best practice but I don't understand why it couldn't at a technical level log at INFO. When I "set" it to log at INFO level it just doesn't log anything. I am using version 2.13.0 of logbook-spring-boot-starter

I have tried setting the application.yml as follows:

logbook:
  exclude:
    - /swagger-ui.html
    - /schema/**
    - /health
    - /favicon.ico
    - /togglz-console/**
  filter.enabled: true
  format.style: json
  write:
    level: INFO
    max-body-size: 8192

I also tried setting

logging.level.org.zalando.logbook to INFO.

Running debug on logback says it propagated the INFO to Logbook and no errors are logged:

|-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@6b3bcab7 - Propagating INFO level on Logger[org.zalando.logbook] onto the JUL framework

Did I miss anything? Can I try anything else?

1

There are 1 best solutions below

0
Infeligo On

If you are using Spring Boot Autoconfiguration, you can take a peek at DefaultHttpLogWriter and create your own HttpLogWriter that logs on your desired level:

@Configuration
public class LoggingConfig {

  @Bean
  public HttpLogWriter httpLogWriter() {
    return new InfoLevelHttpLogWriter();
  }

  static class InfoLevelHttpLogWriter implements HttpLogWriter {

    private final Logger log = LoggerFactory.getLogger(Logbook.class);

    @Override
    public boolean isActive() {
      return log.isInfoEnabled();
    }

    @Override
    public void write(final Precorrelation precorrelation, final String request) {
      log.info(request);
    }

    @Override
    public void write(final Correlation correlation, final String response) {
      log.info(response);
    }

  }

}