Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def requestResponseLog(route: Route) = {
- def requestResponseLogging(loggingAdapter: LoggingAdapter)(req: HttpRequest)(res: Any): Unit = {
- val timeout = 9000.millis
- val bodyAsBytes: Future[ByteString] = req.entity.toStrict(timeout).map(_.data)
- val bodyAsString: Future[String] = bodyAsBytes.map(_.utf8String)
- bodyAsString.onComplete {
- case Success(body) =>
- logger.debug(s"$req\nRequest body: $body\n")
- case Failure(t) =>
- logger.warn(s"error, ${t.getMessage} Failed to get the body for: $req\n")
- }
- res match {
- case Complete(resp) =>
- logger.debug(s"response headers555=${resp.headers}\nresponse status=${resp.status}")
- val bodyAsBytes: Future[ByteString] = resp.entity.toStrict(timeout).map(_.data)
- val bodyAsString: Future[String] = bodyAsBytes.map(_.utf8String)
- bodyAsString.onComplete {
- case Success(value) => {
- logger.debug(s"Response body: ${value}\n")
- }
- case Failure(exception) => {
- logger.warn(s"Failed to get the body for: $resp\n")
- }
- }
- case anythingElse => {
- logger.debug(s"$anythingElse")
- }
- }
- }
- DebuggingDirectives.logRequestResult(LoggingMagnet(requestResponseLogging))(route)
- }
- val bindingFuture = Http().bindAndHandle(requestResponseLog(route), Conf.Server.host, Conf.Server.port)
- logger.info(s"Server online at http://${Conf.Server.host}:${Conf.Server.port}/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement