Add reply logging

This commit is contained in:
Felix Geisendörfer 2013-04-16 19:03:29 +02:00
parent b449132ba4
commit 50dae8f4f6
1 changed files with 5 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"path" "path"
"regexp" "regexp"
"strconv" "strconv"
"time"
) )
// fileRoute matches /files/<id>. Go seems to use \r to terminate header // fileRoute matches /files/<id>. Go seems to use \r to terminate header
@ -66,6 +67,7 @@ func serveHttp() error {
} }
func route(w http.ResponseWriter, r *http.Request) { func route(w http.ResponseWriter, r *http.Request) {
start := time.Now()
log.Printf("request: %s %s", r.Method, r.URL.RequestURI()) log.Printf("request: %s %s", r.Method, r.URL.RequestURI())
w.Header().Set("Server", "tusd") w.Header().Set("Server", "tusd")
@ -99,6 +101,9 @@ func route(w http.ResponseWriter, r *http.Request) {
} else { } else {
reply(w, http.StatusNotFound, "No matching route") reply(w, http.StatusNotFound, "No matching route")
} }
duration := time.Since(start)
log.Printf("finished: %s %s (took %s)", r.Method, r.URL.RequestURI(), duration)
} }
func reply(w http.ResponseWriter, code int, message string) { func reply(w http.ResponseWriter, code int, message string) {