diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-22 20:10:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:16:44 +0800 |
commit | d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch) | |
tree | 17c93170551d3eeabe2935de1765f157007f0dc2 /swarm/api/http | |
parent | 47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff) | |
download | dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.bz2 dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.lz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.xz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip |
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'swarm/api/http')
-rw-r--r-- | swarm/api/http/roundtripper.go | 5 | ||||
-rw-r--r-- | swarm/api/http/server.go | 66 |
2 files changed, 32 insertions, 39 deletions
diff --git a/swarm/api/http/roundtripper.go b/swarm/api/http/roundtripper.go index 7b5bbc883..328177a21 100644 --- a/swarm/api/http/roundtripper.go +++ b/swarm/api/http/roundtripper.go @@ -20,8 +20,7 @@ import ( "fmt" "net/http" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) /* @@ -58,7 +57,7 @@ func (self *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err host = "localhost" } url := fmt.Sprintf("http://%s:%s/%s:/%s/%s", host, self.Port, req.Proto, req.URL.Host, req.URL.Path) - glog.V(logger.Info).Infof("roundtripper: proxying request '%s' to '%s'", req.RequestURI, url) + log.Info(fmt.Sprintf("roundtripper: proxying request '%s' to '%s'", req.RequestURI, url)) reqProxy, err := http.NewRequest(req.Method, url, req.Body) if err != nil { return nil, err diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index b1cea60fc..a61696678 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -21,6 +21,7 @@ package http import ( "bytes" + "fmt" "io" "net/http" "regexp" @@ -29,8 +30,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/swarm/api" "github.com/ethereum/go-ethereum/swarm/storage" "github.com/rs/cors" @@ -86,7 +86,7 @@ func StartHttpServer(api *api.Api, server *Server) { hdlr := c.Handler(serveMux) go http.ListenAndServe(server.Addr, hdlr) - glog.V(logger.Info).Infof("Swarm HTTP proxy started on localhost:%s", server.Addr) + log.Info(fmt.Sprintf("Swarm HTTP proxy started on localhost:%s", server.Addr)) } func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { @@ -100,13 +100,13 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { // return // } // } - glog.V(logger.Debug).Infof("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, requestURL.Host, requestURL.Path, r.Referer(), r.Header.Get("Accept")) + log.Debug(fmt.Sprintf("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, requestURL.Host, requestURL.Path, r.Referer(), r.Header.Get("Accept"))) uri := requestURL.Path var raw, nameresolver bool var proto string // HTTP-based URL protocol handler - glog.V(logger.Debug).Infof("BZZ request URI: '%s'", uri) + log.Debug(fmt.Sprintf("BZZ request URI: '%s'", uri)) path := bzzPrefix.ReplaceAllStringFunc(uri, func(p string) string { proto = p @@ -115,24 +115,18 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { // protocol identification (ugly) if proto == "" { - if glog.V(logger.Error) { - glog.Errorf( - "[BZZ] Swarm: Protocol error in request `%s`.", - uri, - ) - http.Error(w, "Invalid request URL: need access protocol (bzz:/, bzzr:/, bzzi:/) as first element in path.", http.StatusBadRequest) - return - } + log.Error(fmt.Sprintf("[BZZ] Swarm: Protocol error in request `%s`.", uri)) + http.Error(w, "Invalid request URL: need access protocol (bzz:/, bzzr:/, bzzi:/) as first element in path.", http.StatusBadRequest) + return } if len(proto) > 4 { raw = proto[1:5] == "bzzr" nameresolver = proto[1:5] != "bzzi" } - glog.V(logger.Debug).Infof( - "[BZZ] Swarm: %s request over protocol %s '%s' received.", - r.Method, proto, path, - ) + log.Debug("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("[BZZ] Swarm: %s request over protocol %s '%s' received.", r.Method, proto, path) + }}) switch { case r.Method == "POST" || r.Method == "PUT": @@ -142,7 +136,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { } key, err := a.Store(io.LimitReader(r.Body, r.ContentLength), r.ContentLength, nil) if err == nil { - glog.V(logger.Debug).Infof("Content for %v stored", key.Log()) + log.Debug(fmt.Sprintf("Content for %v stored", key.Log())) } else { http.Error(w, err.Error(), http.StatusBadRequest) return @@ -164,10 +158,10 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { path = api.RegularSlashes(path) mime := r.Header.Get("Content-Type") // TODO proper root hash separation - glog.V(logger.Debug).Infof("Modify '%s' to store %v as '%s'.", path, key.Log(), mime) + log.Debug(fmt.Sprintf("Modify '%s' to store %v as '%s'.", path, key.Log(), mime)) newKey, err := a.Modify(path, common.Bytes2Hex(key), mime, nameresolver) if err == nil { - glog.V(logger.Debug).Infof("Swarm replaced manifest by '%s'", newKey) + log.Debug(fmt.Sprintf("Swarm replaced manifest by '%s'", newKey)) w.Header().Set("Content-Type", "text/plain") http.ServeContent(w, r, "", time.Now(), bytes.NewReader([]byte(newKey))) } else { @@ -182,10 +176,10 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { return } else { path = api.RegularSlashes(path) - glog.V(logger.Debug).Infof("Delete '%s'.", path) + log.Debug(fmt.Sprintf("Delete '%s'.", path)) newKey, err := a.Modify(path, "", "", nameresolver) if err == nil { - glog.V(logger.Debug).Infof("Swarm replaced manifest by '%s'", newKey) + log.Debug(fmt.Sprintf("Swarm replaced manifest by '%s'", newKey)) w.Header().Set("Content-Type", "text/plain") http.ServeContent(w, r, "", time.Now(), bytes.NewReader([]byte(newKey))) } else { @@ -206,7 +200,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { if parsedurl == path { key, err := a.Resolve(parsedurl, nameresolver) if err != nil { - glog.V(logger.Error).Infof("%v", err) + log.Error(fmt.Sprintf("%v", err)) http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -226,12 +220,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { quitC := make(chan bool) size, err := reader.Size(quitC) if err != nil { - glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error()) + log.Debug(fmt.Sprintf("Could not determine size: %v", err.Error())) //An error on call to Size means we don't have the root chunk http.Error(w, err.Error(), http.StatusNotFound) return } - glog.V(logger.Debug).Infof("Reading %d bytes.", size) + log.Debug(fmt.Sprintf("Reading %d bytes.", size)) // setting mime type qv := requestURL.Query() @@ -242,11 +236,11 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { w.Header().Set("Content-Type", mimeType) http.ServeContent(w, r, uri, forever(), reader) - glog.V(logger.Debug).Infof("Serve raw content '%s' (%d bytes) as '%s'", uri, size, mimeType) + log.Debug(fmt.Sprintf("Serve raw content '%s' (%d bytes) as '%s'", uri, size, mimeType)) // retrieve path via manifest } else { - glog.V(logger.Debug).Infof("Structured GET request '%s' received.", uri) + log.Debug(fmt.Sprintf("Structured GET request '%s' received.", uri)) // add trailing slash, if missing if rootDocumentUri.MatchString(uri) { http.Redirect(w, r, path+"/", http.StatusFound) @@ -255,10 +249,10 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { reader, mimeType, status, err := a.Get(path, nameresolver) if err != nil { if _, ok := err.(api.ErrResolve); ok { - glog.V(logger.Debug).Infof("%v", err) + log.Debug(fmt.Sprintf("%v", err)) status = http.StatusBadRequest } else { - glog.V(logger.Debug).Infof("error retrieving '%s': %v", uri, err) + log.Debug(fmt.Sprintf("error retrieving '%s': %v", uri, err)) status = http.StatusNotFound } http.Error(w, err.Error(), status) @@ -274,12 +268,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { quitC := make(chan bool) size, err := reader.Size(quitC) if err != nil { - glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error()) + log.Debug(fmt.Sprintf("Could not determine size: %v", err.Error())) //An error on call to Size means we don't have the root chunk http.Error(w, err.Error(), http.StatusNotFound) return } - glog.V(logger.Debug).Infof("Served '%s' (%d bytes) as '%s' (status code: %v)", uri, size, mimeType, status) + log.Debug(fmt.Sprintf("Served '%s' (%d bytes) as '%s' (status code: %v)", uri, size, mimeType, status)) http.ServeContent(w, r, path, forever(), reader) @@ -293,11 +287,11 @@ func (self *sequentialReader) ReadAt(target []byte, off int64) (n int, err error self.lock.Lock() // assert self.pos <= off if self.pos > off { - glog.V(logger.Error).Infof("non-sequential read attempted from sequentialReader; %d > %d", self.pos, off) + log.Error(fmt.Sprintf("non-sequential read attempted from sequentialReader; %d > %d", self.pos, off)) panic("Non-sequential read attempt") } if self.pos != off { - glog.V(logger.Debug).Infof("deferred read in POST at position %d, offset %d.", self.pos, off) + log.Debug(fmt.Sprintf("deferred read in POST at position %d, offset %d.", self.pos, off)) wait := make(chan bool) self.ahead[off] = wait self.lock.Unlock() @@ -313,9 +307,9 @@ func (self *sequentialReader) ReadAt(target []byte, off int64) (n int, err error for localPos < len(target) { n, err = self.reader.Read(target[localPos:]) localPos += n - glog.V(logger.Debug).Infof("Read %d bytes into buffer size %d from POST, error %v.", n, len(target), err) + log.Debug(fmt.Sprintf("Read %d bytes into buffer size %d from POST, error %v.", n, len(target), err)) if err != nil { - glog.V(logger.Debug).Infof("POST stream's reading terminated with %v.", err) + log.Debug(fmt.Sprintf("POST stream's reading terminated with %v.", err)) for i := range self.ahead { self.ahead[i] <- true delete(self.ahead, i) @@ -327,7 +321,7 @@ func (self *sequentialReader) ReadAt(target []byte, off int64) (n int, err error } wait := self.ahead[self.pos] if wait != nil { - glog.V(logger.Debug).Infof("deferred read in POST at position %d triggered.", self.pos) + log.Debug(fmt.Sprintf("deferred read in POST at position %d triggered.", self.pos)) delete(self.ahead, self.pos) close(wait) } |