针对akka-http服务器的调试/日志请求

时间:2020-02-13 19:56:37

标签: akka-http

我有以下测试http,我想从请求中获取默认路由中的所有信息。

class HttpTestServer(port: Int = 6666)(implicit as: ActorSystem, ec: ExecutionContext, mat: ActorMaterializer)
  extends JsonSupport
  with LazyLogging{

  var numRequest: Int = 0
  def start(): Future[ServerBinding] = {
    def routes = {
      // print request information here
      logRequest("test")
      numRequest += 1
      println(s"HttpServer request received: $numRequest")
      complete(Map("key"-> 1.0))
    }
    Http().bindAndHandle(routes, "0.0.0.0", port)
  }

}

我在logback.xml处有以下一行,以在akka-http处启用调试:

<logger name="akka.http" level="DEBUG"/>

作为参考,我使用的是akka-http DebuggingDirective

已更新:我的猜测是LoggingAdapter存在问题,或者LazyLogging与akka LoggingAdapter之间不兼容。如果我打印到stdout可以正常工作:

val logRequestPrintln = DebuggingDirectives.logRequest(LoggingMagnet(_ => println _))
....
logRequestPrintln(complete(Map("key"-> 1.0)))

0 个答案:

没有答案