If you want to capture the body of the SimpleResult response, use this:
def logTime(result: PlainResult): Result = result match { case simple @ SimpleResult(header, content) => { val time = System.currentTimeMillis - start SimpleResult(header, content &> Enumeratee.map(a => { play.Logger.info(s"${rh.method} ${rh.uri} took ${time}ms and returned ${header.status} with body ${a}") simple.writeable.transform(a) })) } case _ => result }
Check mimetype for json:
def logTime(result: PlainResult): Result = { result.header.headers.get(HeaderNames.CONTENT_TYPE) match { case Some(ct) if ct.trim.startsWith(MimeTypes.JSON) => result match { case simple @ SimpleResult(header, content) => val time = System.currentTimeMillis - start SimpleResult(header, content &> Enumeratee.map(a => { play.Logger.info(s"${rh.method} ${rh.uri} took ${time}ms and returned ${header.status} with body ${a}") simple.writeable.transform(a) })) } case ct => result } }
source share