Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. val rejectionHandler = RejectionHandler.default
  2. def logDuration(inner: Route): Route = { ctx =>
  3. val start = System.currentTimeMillis()
  4. // handling rejections here so that we get proper status codes
  5. val innerRejectionsHandled = handleRejections(rejectionHandler)(inner)
  6. mapResponse { resp =>
  7. val d = System.currentTimeMillis() - start
  8. logger.info(s"[${resp.status.intValue()}] ${ctx.request.method.name} ${ctx.request.uri} took: ${d}ms")
  9. resp
  10. }(innerRejectionsHandled)(ctx)
  11. }
  12.  
  13. // improved by @luksow
  14. val rejectionHandler = RejectionHandler.default
  15. val logDuration = extractRequestContext.flatMap { ctx =>
  16. val start = System.currentTimeMillis()
  17. // handling rejections here so that we get proper status codes
  18. mapResponse { resp =>
  19. val d = System.currentTimeMillis() - start
  20. logger.info(s"[${resp.status.intValue()}] ${ctx.request.method.name} ${ctx.request.uri} took: ${d}ms")
  21. resp
  22. } & handleRejections(rejectionHandler)
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement