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

Log nicer

parent a0ce3ee1
...@@ -43,9 +43,10 @@ func (l *loggingResponseWriter) WriteHeader(status int) { ...@@ -43,9 +43,10 @@ func (l *loggingResponseWriter) WriteHeader(status int) {
} }
func (l *loggingResponseWriter) Log(r *http.Request) { 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, r.Host, r.RemoteAddr, l.started,
fmt.Sprintf("%s %s %s", r.Method, r.RequestURI, r.Proto), 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 ...@@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
) )
...@@ -20,6 +21,8 @@ func (p *proxyRoundTripper) RoundTrip(r *http.Request) (res *http.Response, err ...@@ -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 // instead of 500s we catch the RoundTrip error here and inject a
// 502 response. // 502 response.
if err != nil { if err != nil {
logError(fmt.Errorf("proxyRoundTripper: %s %q failed with: %q", r.Method, r.RequestURI, err))
res = &http.Response{ res = &http.Response{
StatusCode: http.StatusBadGateway, StatusCode: http.StatusBadGateway,
Status: http.StatusText(http.StatusBadGateway), Status: http.StatusText(http.StatusBadGateway),
......
...@@ -62,7 +62,7 @@ func (s *sendFileResponseWriter) WriteHeader(status int) { ...@@ -62,7 +62,7 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
s.hijacked = true s.hijacked = true
// Serve the file // 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) content, fi, err := openFile(file)
if err != nil { if err != nil {
http.NotFound(s.rw, s.req) http.NotFound(s.rw, s.req)
......
...@@ -42,7 +42,7 @@ func handleServeFile(documentRoot *string, cache CacheMode, notFoundHandler serv ...@@ -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 { if content == nil || err != nil {
content, fi, err = openFile(file) content, fi, err = openFile(file)
} }
...@@ -64,7 +64,7 @@ func handleServeFile(documentRoot *string, cache CacheMode, notFoundHandler serv ...@@ -64,7 +64,7 @@ func handleServeFile(documentRoot *string, cache CacheMode, notFoundHandler serv
w.Header().Set("Expires", cacheUntil) 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) 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