我正在编写一个播放框架2.1.5访问日志,这样的代码
class AccessLog extends Filter {
def apply(next: (RequestHeader) => Result)(rh: RequestHeader) = {
val start = System.currentTimeMillis
def logTime(result: PlainResult): Result = {
val time = System.currentTimeMillis - start
val contentLength: String = result.header.headers getOrElse("Content-Length", "-")
play.Logger.info("" + rh.method +" " + rh.uri + " took " + " " + time + " ms and returned " + result.header.status + " " + contentLength)
result
}
next(rh) match {
case plain: PlainResult => logTime(plain)
case async: AsyncResult => async.transform(logTime)
}
}
}
我发现很多人都找到了一个播放框架的访问日志,这可以解决任何问题 它可以随时获得响应大小,当您按CTRL + F5时,如果您只按F5,则无法获得" Content-Length"甚至是" Content-Length"在地图中不存在。 任何一个知道吗?