How to customise logging in tapir?

I'm sure this is a ridiculous question... I'm trying to enable tapir's logging as described here:

... but even having looked at the ServerOptions docs, I'm not getting anywhere. My naive assumption from the docs was that it should be something like:

import sttp.tapir.server.akkahttp.AkkaHttpServerOptions
import sttp.tapir.server.interceptor.log.DefaultServerLog

val customServerOptions: AkkaHttpServerOptions = AkkaHttpServerOptions.customInterceptors(
    serverLog = DefaultServerLog(logWhenHandled=true, logAllDecodeFailures=true)

and then


However, this is clearly way off - DefaultServerLog is the wrong type, and would need masses of configuration.

The docs imply this can just be done by setting a few flags, what am I missing?


  • The DefaultServerLog is the default implementation for the ServerLog trait, though it has a couple of fields without default values. These fields specify how to actually perform the logging: DefaultServerLog .doLogWhenHandled etc.

    What you need to do is to get an instance of DefaultServerLog, which is configured to integrate with akka-http. This is available as AkkaHttpServerOptions.Log.defaultServerLog.

    Unfortunately, in 0.19 this was typed too narrowly, not allowing proper customisation. Hence, an ugly cast is needed (this is fixed in the current, stable 1.2 version):

    val customServerOptions: AkkaHttpServerOptions = 
        serverLog = Some(
            .asInstanceOf[DefaultServerLog[LoggingAdapter => Future[Unit]]]
            .copy(logWhenHandled = true, logAllDecodeFailures = true)

    As for the docs, you are right that they might be misleading (they haven't changed much since 0.19), I'll fix that shortly.