aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/client.go39
-rw-r--r--rpc/client_test.go11
-rw-r--r--rpc/ipc.go7
-rw-r--r--rpc/json.go7
-rw-r--r--rpc/server.go14
-rw-r--r--rpc/websocket.go8
6 files changed, 40 insertions, 46 deletions
diff --git a/rpc/client.go b/rpc/client.go
index 269eb78c8..78a6fe789 100644
--- a/rpc/client.go
+++ b/rpc/client.go
@@ -30,8 +30,7 @@ import (
"sync/atomic"
"time"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"golang.org/x/net/context"
)
@@ -408,9 +407,9 @@ func (c *Client) newMessage(method string, paramsIn ...interface{}) (*jsonrpcMes
func (c *Client) send(ctx context.Context, op *requestOp, msg interface{}) error {
select {
case c.requestOp <- op:
- if glog.V(logger.Detail) {
- glog.Info("sending ", msg)
- }
+ log.Trace("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprint("sending ", msg)
+ }})
err := c.write(ctx, msg)
c.sendDone <- err
return err
@@ -445,7 +444,7 @@ func (c *Client) write(ctx context.Context, msg interface{}) error {
func (c *Client) reconnect(ctx context.Context) error {
newconn, err := c.connectFunc(ctx)
if err != nil {
- glog.V(logger.Detail).Infof("reconnect failed: %v", err)
+ log.Trace(fmt.Sprintf("reconnect failed: %v", err))
return err
}
select {
@@ -496,31 +495,31 @@ func (c *Client) dispatch(conn net.Conn) {
for _, msg := range batch {
switch {
case msg.isNotification():
- if glog.V(logger.Detail) {
- glog.Info("<-readResp: notification ", msg)
- }
+ log.Trace("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprint("<-readResp: notification ", msg)
+ }})
c.handleNotification(msg)
case msg.isResponse():
- if glog.V(logger.Detail) {
- glog.Info("<-readResp: response ", msg)
- }
+ log.Trace("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprint("<-readResp: response ", msg)
+ }})
c.handleResponse(msg)
default:
- if glog.V(logger.Debug) {
- glog.Error("<-readResp: dropping weird message", msg)
- }
+ log.Debug("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprint("<-readResp: dropping weird message", msg)
+ }})
// TODO: maybe close
}
}
case err := <-c.readErr:
- glog.V(logger.Debug).Infof("<-readErr: %v", err)
+ log.Debug(fmt.Sprintf("<-readErr: %v", err))
c.closeRequestOps(err)
conn.Close()
reading = false
case newconn := <-c.reconnected:
- glog.V(logger.Debug).Infof("<-reconnected: (reading=%t) %v", reading, conn.RemoteAddr())
+ log.Debug(fmt.Sprintf("<-reconnected: (reading=%t) %v", reading, conn.RemoteAddr()))
if reading {
// Wait for the previous read loop to exit. This is a rare case.
conn.Close()
@@ -577,7 +576,7 @@ func (c *Client) closeRequestOps(err error) {
func (c *Client) handleNotification(msg *jsonrpcMessage) {
if msg.Method != notificationMethod {
- glog.V(logger.Debug).Info("dropping non-subscription message: ", msg)
+ log.Debug(fmt.Sprint("dropping non-subscription message: ", msg))
return
}
var subResult struct {
@@ -585,7 +584,7 @@ func (c *Client) handleNotification(msg *jsonrpcMessage) {
Result json.RawMessage `json:"result"`
}
if err := json.Unmarshal(msg.Params, &subResult); err != nil {
- glog.V(logger.Debug).Info("dropping invalid subscription message: ", msg)
+ log.Debug(fmt.Sprint("dropping invalid subscription message: ", msg))
return
}
if c.subs[subResult.ID] != nil {
@@ -596,7 +595,7 @@ func (c *Client) handleNotification(msg *jsonrpcMessage) {
func (c *Client) handleResponse(msg *jsonrpcMessage) {
op := c.respWait[string(msg.ID)]
if op == nil {
- glog.V(logger.Debug).Infof("unsolicited response %v", msg)
+ log.Debug(fmt.Sprintf("unsolicited response %v", msg))
return
}
delete(c.respWait, string(msg.ID))
diff --git a/rpc/client_test.go b/rpc/client_test.go
index 476c8c6f3..407ed9c06 100644
--- a/rpc/client_test.go
+++ b/rpc/client_test.go
@@ -30,8 +30,7 @@ import (
"time"
"github.com/davecgh/go-spew/spew"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"golang.org/x/net/context"
)
@@ -147,10 +146,6 @@ func testClientCancel(transport string, t *testing.T) {
// You probably want to run with -parallel 1 or comment out
// the call to t.Parallel if you enable the logging.
t.Parallel()
- // glog.SetV(6)
- // glog.SetToStderr(true)
- // defer glog.SetToStderr(false)
- // glog.Infoln("testing ", transport)
// The actual test starts here.
var (
@@ -181,7 +176,7 @@ func testClientCancel(transport string, t *testing.T) {
// The key thing here is that no call will ever complete successfully.
err := client.CallContext(ctx, nil, "service_sleep", 2*maxContextCancelTimeout)
if err != nil {
- glog.V(logger.Debug).Infoln("got expected error:", err)
+ log.Debug(fmt.Sprint("got expected error:", err))
} else {
t.Errorf("no error for call with %v wait time", timeout)
}
@@ -532,7 +527,7 @@ func (l *flakeyListener) Accept() (net.Conn, error) {
if err == nil {
timeout := time.Duration(rand.Int63n(int64(l.maxKillTimeout)))
time.AfterFunc(timeout, func() {
- glog.V(logger.Debug).Infof("killing conn %v after %v", c.LocalAddr(), timeout)
+ log.Debug(fmt.Sprintf("killing conn %v after %v", c.LocalAddr(), timeout))
c.Close()
})
}
diff --git a/rpc/ipc.go b/rpc/ipc.go
index c2b9e3871..3c86d711c 100644
--- a/rpc/ipc.go
+++ b/rpc/ipc.go
@@ -17,10 +17,11 @@
package rpc
import (
+ "fmt"
"net"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
+
"golang.org/x/net/context"
)
@@ -37,7 +38,7 @@ func (srv *Server) ServeListener(l net.Listener) error {
if err != nil {
return err
}
- glog.V(logger.Detail).Infoln("accepted conn", conn.RemoteAddr())
+ log.Trace(fmt.Sprint("accepted conn", conn.RemoteAddr()))
go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions)
}
}
diff --git a/rpc/json.go b/rpc/json.go
index 61a4ddf43..c777fab6e 100644
--- a/rpc/json.go
+++ b/rpc/json.go
@@ -26,8 +26,7 @@ import (
"strings"
"sync"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
const (
@@ -171,7 +170,7 @@ func parseRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) {
// first param must be subscription name
var subscribeMethod [1]string
if err := json.Unmarshal(in.Payload, &subscribeMethod); err != nil {
- glog.V(logger.Debug).Infof("Unable to parse subscription method: %v\n", err)
+ log.Debug(fmt.Sprintf("Unable to parse subscription method: %v\n", err))
return nil, false, &invalidRequestError{"Unable to parse subscription request"}
}
@@ -224,7 +223,7 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error)
// first param must be subscription name
var subscribeMethod [1]string
if err := json.Unmarshal(r.Payload, &subscribeMethod); err != nil {
- glog.V(logger.Debug).Infof("Unable to parse subscription method: %v\n", err)
+ log.Debug(fmt.Sprintf("Unable to parse subscription method: %v\n", err))
return nil, false, &invalidRequestError{"Unable to parse subscription request"}
}
diff --git a/rpc/server.go b/rpc/server.go
index 996c63700..4f9ce541e 100644
--- a/rpc/server.go
+++ b/rpc/server.go
@@ -22,8 +22,8 @@ import (
"runtime"
"sync/atomic"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
+
"golang.org/x/net/context"
"gopkg.in/fatih/set.v0"
)
@@ -149,7 +149,7 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
- glog.Errorln(string(buf))
+ log.Error(fmt.Sprint(string(buf)))
}
s.codecsMu.Lock()
@@ -180,7 +180,7 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
for atomic.LoadInt32(&s.run) == 1 {
reqs, batch, err := s.readRequest(codec)
if err != nil {
- glog.V(logger.Debug).Infof("read error %v\n", err)
+ log.Debug(fmt.Sprintf("read error %v\n", err))
codec.Write(codec.CreateErrorResponse(nil, err))
return nil
}
@@ -236,7 +236,7 @@ func (s *Server) ServeSingleRequest(codec ServerCodec, options CodecOption) {
// close all codecs which will cancel pending requests/subscriptions.
func (s *Server) Stop() {
if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
- glog.V(logger.Debug).Infoln("RPC Server shutdown initiatied")
+ log.Debug(fmt.Sprint("RPC Server shutdown initiatied"))
s.codecsMu.Lock()
defer s.codecsMu.Unlock()
s.codecs.Each(func(c interface{}) bool {
@@ -341,7 +341,7 @@ func (s *Server) exec(ctx context.Context, codec ServerCodec, req *serverRequest
}
if err := codec.Write(response); err != nil {
- glog.V(logger.Error).Infof("%v\n", err)
+ log.Error(fmt.Sprintf("%v\n", err))
codec.Close()
}
@@ -368,7 +368,7 @@ func (s *Server) execBatch(ctx context.Context, codec ServerCodec, requests []*s
}
if err := codec.Write(responses); err != nil {
- glog.V(logger.Error).Infof("%v\n", err)
+ log.Error(fmt.Sprintf("%v\n", err))
codec.Close()
}
diff --git a/rpc/websocket.go b/rpc/websocket.go
index fc3cd0709..f4271fda8 100644
--- a/rpc/websocket.go
+++ b/rpc/websocket.go
@@ -25,8 +25,8 @@ import (
"os"
"strings"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
+
"golang.org/x/net/context"
"golang.org/x/net/websocket"
"gopkg.in/fatih/set.v0"
@@ -76,14 +76,14 @@ func wsHandshakeValidator(allowedOrigins []string) func(*websocket.Config, *http
}
}
- glog.V(logger.Debug).Infof("Allowed origin(s) for WS RPC interface %v\n", origins.List())
+ log.Debug(fmt.Sprintf("Allowed origin(s) for WS RPC interface %v\n", origins.List()))
f := func(cfg *websocket.Config, req *http.Request) error {
origin := strings.ToLower(req.Header.Get("Origin"))
if allowAllOrigins || origins.Has(origin) {
return nil
}
- glog.V(logger.Debug).Infof("origin '%s' not allowed on WS-RPC interface\n", origin)
+ log.Debug(fmt.Sprintf("origin '%s' not allowed on WS-RPC interface\n", origin))
return fmt.Errorf("origin %s not allowed", origin)
}