SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   def requestResponseLog(route: Route) = {
  2.     def requestResponseLogging(loggingAdapter: LoggingAdapter)(req: HttpRequest)(res: Any): Unit = {
  3.       val timeout = 9000.millis
  4.       val bodyAsBytes: Future[ByteString] = req.entity.toStrict(timeout).map(_.data)
  5.       val bodyAsString: Future[String] = bodyAsBytes.map(_.utf8String)
  6.       bodyAsString.onComplete {
  7.         case Success(body) =>
  8.           logger.debug(s"$req\nRequest body: $body\n")
  9.         case Failure(t) =>
  10.           logger.warn(s"error, ${t.getMessage} Failed to get the body for: $req\n")
  11.       }
  12.       res match {
  13.         case Complete(resp) =>
  14.           logger.debug(s"response headers555=${resp.headers}\nresponse status=${resp.status}")
  15.           val bodyAsBytes: Future[ByteString] = resp.entity.toStrict(timeout).map(_.data)
  16.           val bodyAsString: Future[String] = bodyAsBytes.map(_.utf8String)
  17.           bodyAsString.onComplete {
  18.             case Success(value) => {
  19.               logger.debug(s"Response body: ${value}\n")
  20.             }
  21.             case Failure(exception) => {
  22.               logger.warn(s"Failed to get the body for: $resp\n")
  23.             }
  24.           }
  25.         case anythingElse => {
  26.           logger.debug(s"$anythingElse")
  27.         }
  28.       }
  29.     }
  30.     DebuggingDirectives.logRequestResult(LoggingMagnet(requestResponseLogging))(route)
  31.   }
  32.  
  33.   val bindingFuture = Http().bindAndHandle(requestResponseLog(route), Conf.Server.host, Conf.Server.port)
  34.   logger.info(s"Server online at http://${Conf.Server.host}:${Conf.Server.port}/")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top