From 1e28d1bc31002eefcc5f36d3586583c27af50a18 Mon Sep 17 00:00:00 2001 From: Bret Harrison Date: Thu, 6 Jun 2019 11:19:08 -0400 Subject: [PATCH] FABN-1265 NodeSDK remove logging go chaincode Remove the use of the logging provided by the shim. Change-Id: Ifecec571d7ce3e1f6f03e985c662f1bc6116a801 Signed-off-by: Bret Harrison --- .../src/github.com/events_cc/events_cc.go | 20 +++++++++---------- .../src/github.com/example_cc/example_cc.go | 20 +++++++++---------- .../src/github.com/example_cc1/example_cc1.go | 20 +++++++++---------- .../src/github.com/example_cc2/example_cc2.go | 14 ++++++------- .../example_cc_private/example_cc_private.go | 16 +++++++-------- 5 files changed, 41 insertions(+), 49 deletions(-) diff --git a/test/fixtures/chaincode/goLang/src/github.com/events_cc/events_cc.go b/test/fixtures/chaincode/goLang/src/github.com/events_cc/events_cc.go index 36c8a00bcf..e0150e7c23 100644 --- a/test/fixtures/chaincode/goLang/src/github.com/events_cc/events_cc.go +++ b/test/fixtures/chaincode/goLang/src/github.com/events_cc/events_cc.go @@ -23,7 +23,7 @@ import ( "github.com/hyperledger/fabric/core/chaincode/shim" pb "github.com/hyperledger/fabric/protos/peer" ) -var logger = shim.NewLogger("events_cc") + // EventSender example simple Chaincode implementation type EventSender struct { @@ -31,7 +31,7 @@ type EventSender struct { // Init function func (t *EventSender) Init(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("*********** Init ***********") + fmt.Printf("*********** Init ***********") err := stub.PutState("numEvents", []byte("0")) if err != nil { @@ -42,7 +42,7 @@ func (t *EventSender) Init(stub shim.ChaincodeStubInterface) pb.Response { // Invoke - invoke the chaincode func (t *EventSender) Invoke(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("*********** Invoke ***********") + fmt.Printf("*********** Invoke ***********") function, args := stub.GetFunctionAndParameters() if function != "invoke" { @@ -62,7 +62,7 @@ func (t *EventSender) Invoke(stub shim.ChaincodeStubInterface) pb.Response { // Invoke function func (t *EventSender) invoke(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### invoke start ###########") + fmt.Printf("########### invoke start ###########") _ , args := stub.GetFunctionAndParameters() if len(args) != 2 { @@ -77,9 +77,9 @@ func (t *EventSender) invoke(stub shim.ChaincodeStubInterface) pb.Response { tosend := "Event " + string(b) + args[1] eventName := "evtsender" + args[0] - logger.Infof("########### invoke - numEvents:%s\n", numEvents) - logger.Infof("########### invoke - tosend:%s\n", tosend) - logger.Infof("########### invoke - eventName:%s\n", eventName) + fmt.Printf("########### invoke - numEvents:%s\n", numEvents) + fmt.Printf("########### invoke - tosend:%s\n", tosend) + fmt.Printf("########### invoke - eventName:%s\n", eventName) err = stub.PutState("numEvents", []byte(strconv.Itoa(numEvents+1))) if err != nil { @@ -95,7 +95,7 @@ func (t *EventSender) invoke(stub shim.ChaincodeStubInterface) pb.Response { // Clear State function func (t *EventSender) clear(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### clear ###########") + fmt.Printf("########### clear ###########") err := stub.PutState("numEvents", []byte("0")) if err != nil { @@ -106,11 +106,11 @@ func (t *EventSender) clear(stub shim.ChaincodeStubInterface) pb.Response { // Query function func (t *EventSender) query(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### query ###########") + fmt.Printf("########### query ###########") b, err := stub.GetState("numEvents") numEvents, _ := strconv.Atoi(string(b)) - logger.Infof("########### query - numEvents:%s\n", numEvents) + fmt.Printf("########### query - numEvents:%s\n", numEvents) if err != nil { return shim.Error("Failed to get state") diff --git a/test/fixtures/chaincode/goLang/src/github.com/example_cc/example_cc.go b/test/fixtures/chaincode/goLang/src/github.com/example_cc/example_cc.go index f6908318cc..69573e9809 100644 --- a/test/fixtures/chaincode/goLang/src/github.com/example_cc/example_cc.go +++ b/test/fixtures/chaincode/goLang/src/github.com/example_cc/example_cc.go @@ -25,15 +25,13 @@ import ( pb "github.com/hyperledger/fabric/protos/peer" ) -var logger = shim.NewLogger("example_cc0") - // SimpleChaincode example simple Chaincode implementation type SimpleChaincode struct { } // Init - initialize the state func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc0 Init ###########") + fmt.Printf("########### example_cc0 Init ###########") _, args := stub.GetFunctionAndParameters() var A, B string // Entities @@ -55,7 +53,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { if err != nil { return shim.Error("Expecting integer value for asset holding") } - logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval) + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state to the ledger err = stub.PutState(A, []byte(strconv.Itoa(Aval))) @@ -73,12 +71,12 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { // Invoke - Transaction makes payment of X units from A to B func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc0 Invoke ###########") + fmt.Printf("########### example_cc0 Invoke ###########") function, args := stub.GetFunctionAndParameters() - logger.Info("function: ", function) - logger.Info("args: ", args) + fmt.Printf("function: ", function) + fmt.Printf("args: ", args) if function == "delete" { // Deletes an entity from its state @@ -104,7 +102,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { return t.Init(stub) } - logger.Errorf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]) + fmt.Printf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]) return shim.Error(fmt.Sprintf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])) } @@ -149,7 +147,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) } Aval = Aval - X Bval = Bval + X - logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval) + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state back to the ledger err = stub.PutState(A, []byte(strconv.Itoa(Aval))) @@ -207,7 +205,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) } jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" - logger.Infof("Query Response:%s\n", jsonResp) + fmt.Printf("Query Response:%s\n", jsonResp) return shim.Success(Avalbytes) } @@ -219,6 +217,6 @@ func (t *SimpleChaincode) throwError(stub shim.ChaincodeStubInterface, args []st func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { - logger.Errorf("Error starting Simple chaincode: %s", err) + fmt.Printf("Error starting Simple chaincode: %s", err) } } diff --git a/test/fixtures/chaincode/goLang/src/github.com/example_cc1/example_cc1.go b/test/fixtures/chaincode/goLang/src/github.com/example_cc1/example_cc1.go index 06c6184838..ac89579607 100644 --- a/test/fixtures/chaincode/goLang/src/github.com/example_cc1/example_cc1.go +++ b/test/fixtures/chaincode/goLang/src/github.com/example_cc1/example_cc1.go @@ -25,8 +25,6 @@ import ( pb "github.com/hyperledger/fabric/protos/peer" ) -var logger = shim.NewLogger("example_cc1") - // SimpleChaincode example simple Chaincode implementation type SimpleChaincode struct { } @@ -34,7 +32,7 @@ type SimpleChaincode struct { //Init - instantiation of the state func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc1 Init ###########") + fmt.Printf("########### example_cc1 Init ###########") // test the transient map support with chaincode instantiation return t.testTransient(stub) @@ -42,7 +40,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { // Invoke - Transaction makes payment of X units from A to B func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc1 Invoke ###########") + fmt.Printf("########### example_cc1 Invoke ###########") function, args := stub.GetFunctionAndParameters() @@ -71,7 +69,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { return t.testTransient(stub) } - logger.Errorf("Unknown action: %s, check the first argument, must be one of 'delete', 'query', 'echo', 'testTransient' or 'move'", args[0]) + fmt.Printf("Unknown action: %s, check the first argument, must be one of 'delete', 'query', 'echo', 'testTransient' or 'move'", args[0]) return shim.Error(fmt.Sprintf("Unknown action: %s, check the first argument, must be one of 'delete', 'query', 'echo', 'testTransient' or 'move'", args[0])) } @@ -116,7 +114,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) } Aval = Aval - X Bval = Bval + X + 10 //new version chaincode gives a bonus - logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval) + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state back to the ledger err = stub.PutState(A, []byte(strconv.Itoa(Aval))) @@ -174,7 +172,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) } jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" - logger.Infof("Query Response:%s\n", jsonResp) + fmt.Printf("Query Response:%s\n", jsonResp) return shim.Success(Avalbytes) } @@ -187,13 +185,13 @@ func (t *SimpleChaincode) throwError(stub shim.ChaincodeStubInterface, args []st func (t *SimpleChaincode) testTransient(stub shim.ChaincodeStubInterface) pb.Response { tm, err := stub.GetTransient() if err != nil { - logger.Error("Did not find expected transient map in the proposal") + fmt.Printf("Did not find expected transient map in the proposal") return shim.Error("{\"Error\":\"Did not find expected transient map in the proposal}") } v, ok := tm["test"] if !ok { - logger.Error("Did not find expected key \"test\" in the transient map of the proposal") + fmt.Printf("Did not find expected key \"test\" in the transient map of the proposal") return shim.Error("{\"Error\":\"Did not find expected key \"test\" in the transient map of the proposal}") } @@ -203,13 +201,13 @@ func (t *SimpleChaincode) testTransient(stub shim.ChaincodeStubInterface) pb.Res // Used to return what's in the input for testing purposes func (t *SimpleChaincode) echo(stub shim.ChaincodeStubInterface, args []string) pb.Response { - logger.Info("Echo Response\n") + fmt.Printf("Echo Response\n") return shim.Success([]byte(args[0])) } func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { - logger.Errorf("Error starting Simple chaincode: %s", err) + fmt.Printf("Error starting Simple chaincode: %s", err) } } diff --git a/test/fixtures/chaincode/goLang/src/github.com/example_cc2/example_cc2.go b/test/fixtures/chaincode/goLang/src/github.com/example_cc2/example_cc2.go index 45600182ea..1d74e1da57 100644 --- a/test/fixtures/chaincode/goLang/src/github.com/example_cc2/example_cc2.go +++ b/test/fixtures/chaincode/goLang/src/github.com/example_cc2/example_cc2.go @@ -25,8 +25,6 @@ import ( pb "github.com/hyperledger/fabric/protos/peer" ) -var logger = shim.NewLogger("example_cc2") - // SimpleChaincode example simple Chaincode implementation type SimpleChaincode struct { } @@ -34,7 +32,7 @@ type SimpleChaincode struct { // Init - Re-initialize one of the parties' asset holdings func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc2 Init ###########") + fmt.Printf("########### example_cc2 Init ###########") _, args := stub.GetFunctionAndParameters() var A string // Entities @@ -47,7 +45,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { if err != nil { return shim.Error("Expecting integer value for asset holding") } - logger.Info("Aval = %d\n", Aval) + fmt.Printf("Aval = %d\n", Aval) // Write the state to the ledger err = stub.PutState(A, []byte(strconv.Itoa(Aval))) @@ -60,7 +58,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { // Invoke - Transaction makes payment of X units from A to B func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc1 Invoke ###########") + fmt.Printf("########### example_cc1 Invoke ###########") function, args := stub.GetFunctionAndParameters() @@ -69,7 +67,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { return t.query(stub, args) } - logger.Errorf("Unknown action: %s, check the first argument, must be 'query'", args[0]) + fmt.Printf("Unknown action: %s, check the first argument, must be 'query'", args[0]) return shim.Error(fmt.Sprintf("Unknown action: %s, check the first argument, must be 'query'", args[0])) } @@ -98,13 +96,13 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) } jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" - logger.Infof("Query Response:%s\n", jsonResp) + fmt.Printf("Query Response:%s\n", jsonResp) return shim.Success(Avalbytes) } func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { - logger.Errorf("Error starting Simple chaincode: %s", err) + fmt.Printf("Error starting Simple chaincode: %s", err) } } diff --git a/test/fixtures/chaincode/goLang/src/github.com/example_cc_private/example_cc_private.go b/test/fixtures/chaincode/goLang/src/github.com/example_cc_private/example_cc_private.go index 3a5d64412c..4c208fa10b 100755 --- a/test/fixtures/chaincode/goLang/src/github.com/example_cc_private/example_cc_private.go +++ b/test/fixtures/chaincode/goLang/src/github.com/example_cc_private/example_cc_private.go @@ -27,8 +27,6 @@ import ( pb "github.com/hyperledger/fabric/protos/peer" ) -var logger = shim.NewLogger("example_cc0_private") - // SimpleChaincode example simple Chaincode implementation type SimpleChaincode struct { } @@ -51,7 +49,7 @@ type sensitiveCol struct { // Init - initialize the state func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc0_private Init ###########") + fmt.Printf("########### example_cc0_private Init ###########") _, args := stub.GetFunctionAndParameters() var A, B string // Entities @@ -73,7 +71,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { if err != nil { return shim.Error("Expecting integer value for asset holding") } - logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval) + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state to the ledger err = stub.PutState(A, []byte(strconv.Itoa(Aval))) @@ -91,7 +89,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { // Invoke - Transaction makes payment of X units from A to B func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { - logger.Info("########### example_cc0_private Invoke ###########") + fmt.Printf("########### example_cc0_private Invoke ###########") function, args := stub.GetFunctionAndParameters() @@ -125,7 +123,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { return t.querySensitive(stub, args) } - logger.Errorf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]) + fmt.Printf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0]) return shim.Error(fmt.Sprintf("Unknown action, check the first argument, must be one of 'delete', 'query', or 'move'. But got: %v", args[0])) } @@ -170,7 +168,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) } Aval = Aval - X Bval = Bval + X - logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval) + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state back to the ledger err = stub.PutState(A, []byte(strconv.Itoa(Aval))) @@ -318,7 +316,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) } jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" - logger.Infof("Query Response:%s\n", jsonResp) + fmt.Printf("Query Response:%s\n", jsonResp) return shim.Success(Avalbytes) } @@ -384,6 +382,6 @@ func (t *SimpleChaincode) querySensitive(stub shim.ChaincodeStubInterface, args func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { - logger.Errorf("Error starting Simple chaincode: %s", err) + fmt.Printf("Error starting Simple chaincode: %s", err) } }