Add logging to the file-server

This commit is contained in:
Leonid Bugaev
2016-06-08 14:38:09 +05:00
parent 0fb8cec69b
commit 35696a49c2
2 changed files with 12 additions and 2 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ TEST = TestRawListenerBench
VERSION = DEV-$(shell date +%s)
LDFLAGS = -ldflags "-X main.VERSION=$(VERSION) -extldflags \"-static\""
MAC_LDFLAGS = -ldflags "-X main.VERSION=$(VERSION)"
FADDR = ":8000"
release: release-x64 release-mac
@@ -68,7 +69,7 @@ run-3:
sudo -E go run $(SOURCE) --input-tcp :27001 --output-stdout
file-server:
go run $(SOURCE) file-server :8000
go run $(SOURCE) file-server $(FADDR)
record:
$(RUN) go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug
+10 -1
View File
@@ -15,6 +15,7 @@ import (
"syscall"
"time"
"net/http"
"net/http/httputil"
)
var (
@@ -23,6 +24,14 @@ var (
memprofile = flag.String("memprofile", "", "write memory profile to this file")
)
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rb, _ := httputil.DumpRequest(r, false)
log.Println(string(rb))
next.ServeHTTP(w, r)
})
}
func main() {
// // Don't exit on panic
// defer func() {
@@ -45,7 +54,7 @@ func main() {
log.Println("Started example file server for current dirrectory on address ", args[1])
log.Fatal(http.ListenAndServe(args[1], http.FileServer(http.Dir(dir))))
log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(http.FileServer(http.Dir(dir)))))
} else {
flag.Parse()
InitPlugins()