Last active
December 11, 2015 00:09
-
-
Save francisdb/4514950 to your computer and use it in GitHub Desktop.
Logging WS requests in playframework scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll have to fork the play WS class then. Would have been nice if the async httpcliend had a global hook