Explorar o código

Merge pull request #1918 from xiang90/http_no_logging

etcdmain: discard the http server logging
Xiang Li %!s(int64=11) %!d(string=hai) anos
pai
achega
ec777ebd28
Modificáronse 2 ficheiros con 23 adicións e 2 borrados
  1. 2 2
      etcdmain/etcd.go
  2. 21 0
      etcdmain/http.go

+ 2 - 2
etcdmain/etcd.go

@@ -319,13 +319,13 @@ func startEtcd() (<-chan struct{}, error) {
 	// Start the peer server in a goroutine
 	for _, l := range plns {
 		go func(l net.Listener) {
-			log.Fatal(http.Serve(l, ph))
+			log.Fatal(serveHTTP(l, ph))
 		}(l)
 	}
 	// Start a client server goroutine for each listen address
 	for _, l := range clns {
 		go func(l net.Listener) {
-			log.Fatal(http.Serve(l, ch))
+			log.Fatal(serveHTTP(l, ch))
 		}(l)
 	}
 	return s.StopNotify(), nil

+ 21 - 0
etcdmain/http.go

@@ -0,0 +1,21 @@
+package etcdmain
+
+import (
+	"io/ioutil"
+	"log"
+	"net"
+	"net/http"
+)
+
+// serveHTTP accepts incoming HTTP connections on the listener l,
+// creating a new service goroutine for each. The service goroutines
+// read requests and then call handler to reply to them.
+func serveHTTP(l net.Listener, handler http.Handler) error {
+	logger := log.New(ioutil.Discard, "etcdhttp", 0)
+	// TODO: add debug flag; enable logging when debug flag is set
+	srv := &http.Server{
+		Handler:  handler,
+		ErrorLog: logger, // do not log user error
+	}
+	return srv.Serve(l)
+}