From f776b9d5fa3577fe2fdaa3d2ef9d48adee329f9c Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Tue, 8 Aug 2017 15:38:21 -0400 Subject: net/http: log Readdir error to Server.ErrorLog Now that issue #12438 is resolved, this TODO can be completed. Create a logf helper, which is similar to Server.logf method, but takes a *Request to infer the *Server and its ErrorLog from. Update documentation of Server.ErrorLog to mention a new type of errors that may be logged to it. Also update a statement in documentation of Server.ErrorLog from: // If nil, logging goes to os.Stderr via the log package's // standard logger. To: // If nil, logging is done via the log package's standard logger. The motivation for doing so is to avoid making inaccurate claims. Logging may not go to os.Stderr if anyone overrides the log package's default output via https://godoc.org/log#SetOutput. Saying that the standard logger is used should be sufficient to explain the behavior, and users can infer that os.Stderr is used by default, unless it's changed. Updates #12438. Change-Id: I3a4b0db51d652fd25fb2065fbc2157a3dec4dd38 Reviewed-on: https://go-review.googlesource.com/53950 Reviewed-by: Brad Fitzpatrick --- src/net/http/fs.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/net/http/fs.go') diff --git a/src/net/http/fs.go b/src/net/http/fs.go index cda08b4a5b..a5881e98b3 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -98,12 +98,10 @@ type File interface { Stat() (os.FileInfo, error) } -func dirList(w ResponseWriter, f File) { +func dirList(w ResponseWriter, r *Request, f File) { dirs, err := f.Readdir(-1) if err != nil { - // TODO: log err.Error() to the Server.ErrorLog, once it's possible - // for a handler to get at its Server via the ResponseWriter. See - // Issue 12438. + logf(r, "http: error reading directory: %v", err) Error(w, "Error reading directory", StatusInternalServerError) return } @@ -615,7 +613,7 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec return } w.Header().Set("Last-Modified", d.ModTime().UTC().Format(TimeFormat)) - dirList(w, f) + dirList(w, r, f) return } -- cgit v1.3