Feature #4194
Updated by Tom Clegg over 10 years ago
Currently, each handler is expected to implement its own logging. As a result, log formats are inconsistent, handlers get written without any logs at all, and at best there is much code repetition.
Instead, the router should implement a generic request/response logging system with the following features.
* Every transaction uses the same format, e.g., "ipaddr resp_status resp_size elapsed uri err"
* Individual handlers do not worry about logging or returning error codes -- they just set the response status using http.Error(), http.StatusOK, etc., and let the logging system figure out what to say by inspecting the request and response objects.
Implementation:
* Perhaps this:
** <pre>
// Tell the built-in HTTP server to direct all requests to the REST
// router.
http.Handle("/", MakeRESTRouter())
</pre>
* ...can be replaced with something like this?
** <pre>
// The built-in HTTP server will pass each request to this function,
// which forwards the request to the REST router and logs the outcome.
router := MakeRESTRouter()
http.HandleFunc("/", func(resp ResponseWriter, req *Request) {
router.ServeHTTP(resp, req)
// log stuff here!
})
</pre>