我有以下测试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)))