Skip to content

Commit

Permalink
[FAB-3528] peer/channel package not using logging
Browse files Browse the repository at this point in the history
In peer/channel  package replaced "fmt.Println"

and "fmt.Printf" with  proper logging for files

channel.go
deliverclient.go
join.go
list.go

Change-Id: I820cc977e6745e4e9ce4f66e9d32f2cf6598bc58
Signed-off-by: Dinesh Kumar <dinesh.kumar@itpeoplecorp.com>
  • Loading branch information
Dinesh Kumar authored and raidineshitpeople committed Jun 5, 2017
1 parent b4ed012 commit 2128ea0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
8 changes: 5 additions & 3 deletions peer/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strings"

"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/peer/common"
ab "github.com/hyperledger/fabric/protos/orderer"
Expand All @@ -36,6 +37,8 @@ const (
longDes = "Operate a channel: create|fetch|update|join|list."
)

var logger = flogging.MustGetLogger("channelCmd")

type OrdererRequirement bool
type EndorserRequirement bool

Expand Down Expand Up @@ -151,12 +154,11 @@ func InitCmdFactory(isEndorserRequired EndorserRequirement, isOrdererRequired Or

client, err := ab.NewAtomicBroadcastClient(conn).Deliver(context.TODO())
if err != nil {
fmt.Println("Error connecting:", err)
return nil, err
return nil, fmt.Errorf("Error connecting due to %s", err)
}

cmdFact.DeliverClient = newDeliverClient(conn, client, chainID)
}

logger.Infof("Endorser and orderer connections initialized")
return cmdFact, nil
}
16 changes: 7 additions & 9 deletions peer/channel/deliverclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func seekHelper(chainID string, position *ab.SeekPosition) *common.Envelope {
epoch := uint64(0)
env, err := utils.CreateSignedEnvelope(common.HeaderType_CONFIG_UPDATE, chainID, localmsp.NewSigner(), seekInfo, msgVersion, epoch)
if err != nil {
fmt.Printf("Error signing envelope %s\n", err)
logger.Errorf("Error signing envelope: %s", err)
return nil
}
return env
Expand All @@ -77,16 +77,15 @@ func (r *deliverClient) seekNewest() error {
func (r *deliverClient) readBlock() (*common.Block, error) {
msg, err := r.client.Recv()
if err != nil {
fmt.Println("Error receiving:", err)
return nil, err
return nil, fmt.Errorf("Error receiving: %s", err)
}

switch t := msg.Type.(type) {
case *ab.DeliverResponse_Status:
fmt.Println("Got status ", t)
logger.Debugf("Got status:%T ", t)
return nil, fmt.Errorf("can't read the block")
case *ab.DeliverResponse_Block:
fmt.Println("Received block: ", t.Block.Header.Number)
logger.Debugf("Received block:%v ", t.Block.Header.Number)
r.client.Recv() // Flush the success message
return t.Block, nil
default:
Expand All @@ -97,7 +96,7 @@ func (r *deliverClient) readBlock() (*common.Block, error) {
func (r *deliverClient) getSpecifiedBlock(num uint64) (*common.Block, error) {
err := r.seekSpecified(num)
if err != nil {
fmt.Println("Received error:", err)
logger.Errorf("Received error: %s", err)
return nil, err
}

Expand All @@ -107,8 +106,7 @@ func (r *deliverClient) getSpecifiedBlock(num uint64) (*common.Block, error) {
func (r *deliverClient) getOldestBlock() (*common.Block, error) {
err := r.seekOldest()
if err != nil {
fmt.Println("Received error:", err)
return nil, err
return nil, fmt.Errorf("Received error: %s ", err)
}

return r.readBlock()
Expand All @@ -117,7 +115,7 @@ func (r *deliverClient) getOldestBlock() (*common.Block, error) {
func (r *deliverClient) getNewestBlock() (*common.Block, error) {
err := r.seekNewest()
if err != nil {
fmt.Println("Received error:", err)
logger.Errorf("Received error: %s", err)
return nil, err
}

Expand Down
7 changes: 2 additions & 5 deletions peer/channel/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ func (e ProposalFailedErr) Error() string {

func getJoinCCSpec() (*pb.ChaincodeSpec, error) {
if genesisBlockPath == common.UndefinedParamValue {
return nil, errors.New("Must supply genesis block file.")
return nil, errors.New("Must supply genesis block file")
}

gb, err := ioutil.ReadFile(genesisBlockPath)
if err != nil {
return nil, GBFileNotFoundErr(err.Error())
}

// Build the spec
input := &pb.ChaincodeInput{Args: [][]byte{[]byte(cscc.JoinChain), gb}}

Expand Down Expand Up @@ -119,9 +118,7 @@ func executeJoin(cf *ChannelCmdFactory) (err error) {
if proposalResp.Response.Status != 0 && proposalResp.Response.Status != 200 {
return ProposalFailedErr(fmt.Sprintf("bad proposal response %d", proposalResp.Response.Status))
}

fmt.Println("Peer joined the channel!")

logger.Infof("Peer joined the channel!")
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions peer/channel/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ func list(cf *ChannelCmdFactory) error {
if channels, err := client.getChannels(); err != nil {
return err
} else {
fmt.Println("Channels peers has joined to:")
logger.Infof("Channels peers has joined to: ")

for _, channel := range channels {
fmt.Println("\t", channel.ChannelId)
logger.Infof("%s ", channel.ChannelId)
}
}

Expand Down

0 comments on commit 2128ea0

Please sign in to comment.