1

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

https://tapir.softwaremill.com/en/v0.19.0-m4/server/debugging.html

... 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

AkkaHttpServerInterpreter(customServerOptions).toRoute(...)

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?

user3468054
  • 610
  • 4
  • 11
  • 1
    are you using 0.19.0-M4 in your project? that's quite an old version – adamw Dec 20 '22 at 16:46
  • Yes. It's a project I recently inherited (I'm completely new to tapir, and indeed akka). So yes, upgrading would be a good thing to do - I'd just rather it wasn't a last-day-before-Christmas problem :) – user3468054 Dec 20 '22 at 16:48

1 Answers1

4

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 = 
  AkkaHttpServerOptions.customInterceptors(
    serverLog = Some(
      AkkaHttpServerOptions.Log.defaultServerLog
        .asInstanceOf[DefaultServerLog[LoggingAdapter => Future[Unit]]]
        .copy(logWhenHandled = true, logAllDecodeFailures = true)
    )
  )

AkkaHttpServerInterpreter(customServerOptions).toRoute(???)

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.

adamw
  • 8,038
  • 4
  • 28
  • 32
  • 1
    Here's the commit fixing the docs: https://github.com/softwaremill/tapir/commit/cd60ac941d047b3207fe11c3491d9ca7cc80a910 – adamw Dec 20 '22 at 19:52