【发布时间】:2017-08-30 16:33:33
【问题描述】:
我一直在尝试追踪我的应用程序发送的一些 HTTP 500。它们在localhost_access_log.txt 中显示为:
127.0.0.1 - - [30/Aug/2017:16:27:46 +0000] "POST /user/174 HTTP/1.1" 500 1
所以我在我的应用程序中添加了日志记录,以捕获所有类型为 5xx 的异常和响应。这些日志永远不会被填充。另外,如您所见,响应的长度是一个字节,绝不应该是这种情况。我使用的 Web 框架 Lift 将返回比 5xx 更大的响应。
我正在尝试解决所有问题:
LiftRules.onEndServicing.append {
case (req, Full(resp)) => {
resp.toResponse.code.toString match {
case internalServerError if(internalServerError.startsWith("5")) => requestLogError(req, resp.toString)
case _ =>
}
}
case _ =>
}
LiftRules.exceptionHandler.prepend {
case (runMode, req, exception) =>
requestLogError(req, Throwables.getStackTraceAsString(exception))
XhtmlResponse((<html> <body>Something unexpected happened while serving the page at {req.uri}</body> </html>), S.htmlProperties.docType, List("Content-Type" -> "text/html; charset=utf-8"), Nil, 500, S.legacyIeCompatibilityMode)
}
所以requestLog 中没有记录任何内容,我想知道它是否会影响我的代码。
如何更好地登录 Tomcat 以查看根本原因?
catalina.out 中也没有任何内容。
【问题讨论】:
-
这很奇怪。
localhost_access_log.txt是由 Tomcat 生成的还是由 nginx 之类的反向代理生成的? -
在
org.apache.catalina.valves.AccessLogValve中定义为日志文件,所以是Tomcat。 -
为了一些额外的好处,请尝试为
LiftRules.early提供一个执行req.context.setAttribute("startedLiftProcessing", true)的函数。然后你应该能够将该属性添加到日志中作为%{startedLiftProcessing}r或%{startedLiftProcessing}s,我相信。哪个 Tomcat 版本? -
Apache Tomcat/8.0.41(无法控制 - 这是 Elastic Beanstalk 选择的任何内容)。 -
或许
-是个提示——可能没有请求数据?仍然没有解释为什么 Lift 不会记录该异常:/
标签: java scala tomcat tomcat8 lift