如果我的服务器处理请求并将响应代码写入大于 399,我想记录错误跟踪:
bm.Use(func(res http.ResponseWriter, req *http.Request, c martini.Context, log *logging.Logger, statter statsd.Statter) {
start := time.Now()
rw := res.(martini.ResponseWriter)
c.Next() // do all the middleware handler stuff
if res.(martini.ResponseWriter).Status() > 399 {
log.Warning("%v", "print response here") // how to read response here
}
})
给定状态码,有没有办法读取响应?如果我们将错误发送回客户端,我如何拦截错误消息并记录它?