replace log by singleton logging

pull/359/head
Minh Doan 6 years ago committed by Minh Doan
parent 71e58a4c8a
commit 7a37836b35
  1. 17
      api/services/syncing/downloader/client.go
  2. 1
      p2p/host/message.go

@ -4,12 +4,11 @@ import (
"context" "context"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"log"
"time" "time"
"google.golang.org/grpc"
pb "github.com/harmony-one/harmony/api/services/syncing/downloader/proto" pb "github.com/harmony-one/harmony/api/services/syncing/downloader/proto"
"github.com/harmony-one/harmony/internal/utils"
"google.golang.org/grpc"
) )
// Client is the client model for downloader package. // Client is the client model for downloader package.
@ -26,7 +25,7 @@ func ClientSetup(ip, port string) *Client {
var err error var err error
client.conn, err = grpc.Dial(fmt.Sprintf("%s:%s", ip, port), client.opts...) client.conn, err = grpc.Dial(fmt.Sprintf("%s:%s", ip, port), client.opts...)
if err != nil { if err != nil {
log.Printf("client.go:ClientSetup fail to dial: %v", err) utils.GetLogInstance().Info("client.go:ClientSetup fail to dial: ", "error", err)
return nil return nil
} }
@ -38,7 +37,7 @@ func ClientSetup(ip, port string) *Client {
func (client *Client) Close() { func (client *Client) Close() {
err := client.conn.Close() err := client.conn.Close()
if err != nil { if err != nil {
log.Printf("unable to close connection %v with error %v ", client.conn, err) utils.GetLogInstance().Info("unable to close connection ")
} }
} }
@ -49,7 +48,7 @@ func (client *Client) GetBlockHashes(startHash []byte) *pb.DownloaderResponse {
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER, BlockHash: startHash} request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER, BlockHash: startHash}
response, err := client.dlClient.Query(ctx, request) response, err := client.dlClient.Query(ctx, request)
if err != nil { if err != nil {
log.Printf("[SYNC] GetBlockHashes query failed with error %v", err) utils.GetLogInstance().Info("[SYNC] GetBlockHashes query failed", "error", err)
} }
return response return response
} }
@ -66,7 +65,7 @@ func (client *Client) GetBlocks(hashes [][]byte) *pb.DownloaderResponse {
} }
response, err := client.dlClient.Query(ctx, request) response, err := client.dlClient.Query(ctx, request)
if err != nil { if err != nil {
log.Printf("[SYNC] downloader/client.go:GetBlocks query failed with error %v", err) utils.GetLogInstance().Info("[SYNC] downloader/client.go:GetBlocks query failed.", "error", err)
} }
return response return response
} }
@ -81,7 +80,7 @@ func (client *Client) Register(hash []byte) *pb.DownloaderResponse {
copy(request.PeerHash, hash) copy(request.PeerHash, hash)
response, err := client.dlClient.Query(ctx, request) response, err := client.dlClient.Query(ctx, request)
if err != nil { if err != nil {
log.Printf("[SYNC] client.go:Register failed with code %v", err) utils.GetLogInstance().Info("[SYNC] client.go:Register failed.", "error", err)
} }
return response return response
} }
@ -105,7 +104,7 @@ func (client *Client) PushNewBlock(peerID uint32, blockHash []byte, timeout bool
response, err := client.dlClient.Query(ctx, request) response, err := client.dlClient.Query(ctx, request)
if err != nil { if err != nil {
log.Printf("[SYNC] unable to send new block to unsync node with error: %v", err) utils.GetLogInstance().Info("[SYNC] unable to send new block to unsync node", "error", err)
} }
return response return response
} }

@ -106,7 +106,6 @@ func send(h p2p.Host, peer p2p.Peer, message []byte, lostPeer chan p2p.Peer) {
// DialWithSocketClient joins host port and establishes connection // DialWithSocketClient joins host port and establishes connection
func DialWithSocketClient(ip, port string) (conn net.Conn, err error) { func DialWithSocketClient(ip, port string) (conn net.Conn, err error) {
//log.Printf("Sending message to ip %s and port %s\n", ip, port)
addr := net.JoinHostPort(ip, port) addr := net.JoinHostPort(ip, port)
conn, err = net.Dial("tcp", addr) conn, err = net.Dial("tcp", addr)
return return

Loading…
Cancel
Save