-
Notifications
You must be signed in to change notification settings - Fork 17.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: net/http: log errors during serve() #56028
Comments
If these are logged via |
// CountError, if non-nil, is called on HTTP/2 server errors.
// It's intended to increment a metric for monitoring, such
// as an expvar or Prometheus metric.
// The errType consists of only ASCII word characters.
CountError func(errType string) Would a |
Hi everybody. Are there any chances, this FR is going to be addressed? |
If this should be categorized as something other than a proposal, I apologize, feel free to change as necessary. It didn't seem quite like a bug, and nothing else seemed like a good fit.
Current State
If
http.Serve
encounters an error while serving a request (but before sending it to any handlers viaServeHTTP
), there are cases where HTTP responses are sent to clients, with no logging performed to inform the operator that a request even occurred. Notable cases include:http.Server
has no hooks in place to allow for custom access log messages for these requests, but does have anErrorLog
attribute. However, it is not used to log any of these failures. It is used to log other per-request errors, such as the following:Proposals
Quick and Easy
We add
logf()
calls to theserve()
function that log the failures being encountered prior to sending responses.Thorough and Flexible
http.AccessLogger
interface with one function:ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
AccessLog http.AccessLogger
attribute tohttp.Server
(defaulting to nil) that if present is called when writing any responses to the client. Currently consumers ofhttp.Server
need to provide access logging functionality on their own, but are unable to catch all responses sent. This would allow for a realitively easy drop-in + opt-in replacement for existing access log handlers.The text was updated successfully, but these errors were encountered: