Skip to content

Instantly share code, notes, and snippets.

@francisdb
Last active December 11, 2015 00:09
Show Gist options
  • Save francisdb/4514950 to your computer and use it in GitHub Desktop.
Save francisdb/4514950 to your computer and use it in GitHub Desktop.
Logging WS requests in playframework scala
// I'm looking for a better solution for the time logging (preferable in a transparent way)
private def logTime(message: String, promise: Future[Response]) = {
// not 100% ok, request is already running
// might even not be started yet
val now = System.currentTimeMillis
promise.onRedeem { response =>
val time = System.currentTimeMillis - now
logger.info(message + " => " + response.status + " " + time + "ms " + response.body.length + "b")
}
promise
}
def user(slug: String): Future[Option[User]] = {
val url = ...
logTime(url,
WS.url(url).get()
).map {
...handle response
}
}
@francisdb
Copy link
Author

I'll have to fork the play WS class then. Would have been nice if the async httpcliend had a global hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment