From 3a83ab1b71aac24a8ee35875a8822c80451115e5 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 11 Dec 2014 15:11:20 -0800 Subject: [PATCH] etcdmain: discard the http server logging --- etcdmain/etcd.go | 4 ++-- etcdmain/http.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 etcdmain/http.go diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index 6fd2d64db..9f0211d54 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -313,13 +313,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 diff --git a/etcdmain/http.go b/etcdmain/http.go new file mode 100644 index 000000000..23a252936 --- /dev/null +++ b/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) +}