Commit 3be3f01d authored by Kamil Trzcinski's avatar Kamil Trzcinski

Log nicer

parent a0ce3ee1
......@@ -43,9 +43,10 @@ func (l *loggingResponseWriter) WriteHeader(status int) {
}
func (l *loggingResponseWriter) Log(r *http.Request) {
fmt.Printf("%s %s - - [%s] %q %d %d %q %q\n",
duration := time.Since(l.started)
fmt.Printf("%s %s - - [%s] %q %d %d %q %q %f\n",
r.Host, r.RemoteAddr, l.started,
fmt.Sprintf("%s %s %s", r.Method, r.RequestURI, r.Proto),
l.status, l.written, r.Referer(), r.UserAgent(),
l.status, l.written, r.Referer(), r.UserAgent(), duration.Seconds(),
)
}
......@@ -2,6 +2,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
......@@ -20,6 +21,8 @@ func (p *proxyRoundTripper) RoundTrip(r *http.Request) (res *http.Response, err
// instead of 500s we catch the RoundTrip error here and inject a
// 502 response.
if err != nil {
logError(fmt.Errorf("proxyRoundTripper: %s %q failed with: %q", r.Method, r.RequestURI, err))
res = &http.Response{
StatusCode: http.StatusBadGateway,
Status: http.StatusText(http.StatusBadGateway),
......
......@@ -62,7 +62,7 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
s.hijacked = true
// Serve the file
log.Printf("SendFile: serving %q", file)
log.Printf("Send file %q for %s %q", file, s.req.Method, s.req.RequestURI)
content, fi, err := openFile(file)
if err != nil {
http.NotFound(s.rw, s.req)
......
......@@ -42,7 +42,7 @@ func handleServeFile(documentRoot *string, cache CacheMode, notFoundHandler serv
}
}
// If not found open the file
// If not found, open the original file
if content == nil || err != nil {
content, fi, err = openFile(file)
}
......@@ -64,7 +64,7 @@ func handleServeFile(documentRoot *string, cache CacheMode, notFoundHandler serv
w.Header().Set("Expires", cacheUntil)
}
log.Printf("StaticFile: serving %q %q", file, w.Header().Get("Content-Encoding"))
log.Printf("Send static file %q (%q) for %s %q", file, w.Header().Get("Content-Encoding"), r.Method, r.RequestURI)
http.ServeContent(w, r.Request, filepath.Base(file), fi.ModTime(), content)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment