The official documentation provides an overview of how the field is used:
// ErrorLog specifies an optional logger for errors accepting
// connections, unexpected behavior from handlers, and
// underlying FileSystem errors.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger // Go 1.3
In practice, the field is accessed in the *http.Server
's logf
method. You can check where that method is called. In short (not exhaustive):
- on panics serving HTTP requests (
conn
's serve(ctx context.Context)
)
- on TLS handshake errors
- on the server's
Serve(l net.Listener) error
errors
- on writing non-empty data to the response, if the connection was hijacked
- if the
Content-Length
is invalid
- if you call
WriteHeader(code int)
on the same response more than once
- if
Content-Length
and non-identity
Transfer-Encoding
headers are used together