dongqun9403
2019-03-15 18:15 阅读 268
已采纳

在Hyperledger架构中,如何打印出链码函数的消息和日志?

I want to test my chaincode by Golang, so I have used Hyperledger fabric chaincodedev test.

All functions of chaincode (invoke, query, etc.) worked, but there are no logs and messages of chaincode on console.

Logging is set to "debug" in every case.

I want to print out result message of invoke, query on console, but just print out message: "myc"; "myc"; "myc"; ...

2019-03-15 18:07:04.550 UTC [shim] setupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2019-03-15 18:07:04.550 UTC [shim] setupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...
2019-03-15 18:07:04.551 UTC [bccsp] initBCCSP -> DEBU 001 Initialize BCCSP [SW]
2019-03-15 18:07:04.551 UTC [grpc] DialContext -> DEBU 002 parsed scheme: ""
2019-03-15 18:07:04.551 UTC [grpc] DialContext -> DEBU 003 scheme "" not registered, fallback to default scheme
2019-03-15 18:07:04.551 UTC [grpc] watcher -> DEBU 004 ccResolverWrapper: sending new addresses to cc: [{peer:7052 0  <nil>}]
2019-03-15 18:07:04.551 UTC [grpc] switchBalancer -> DEBU 005 ClientConn switching balancer to "pick_first"
2019-03-15 18:07:04.551 UTC [grpc] HandleSubConnStateChange -> DEBU 006 pickfirstBalancer: HandleSubConnStateChange: 0xc00038eca0, CONNECTING
2019-03-15 18:07:04.552 UTC [grpc] HandleSubConnStateChange -> DEBU 007 pickfirstBalancer: HandleSubConnStateChange: 0xc00038eca0, READY

myc myc myc myc myc myc myc

enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douhuang2673 douhuang2673 2019-03-16 02:02

    It's look like fmt.Println output.

    But you can user

    shim.NewLogger("YOUR_COMPONENT_NAME")
    

    You can found an example of shim logger :

    https://github.com/IBM-Blockchain-Archive/fabric-boilerplate/blob/master/blockchain/src/build-chaincode/chaincode.go

    点赞 评论 复制链接分享
  • douhuiyan2772 douhuiyan2772 2019-03-27 12:32

    The logs for chaincodes are in their respective containers. So for a chaincode called mycc at version 1.0 on peer0 of org, I'd run:

    docker logs -f dev-peer0.org.example.com-mycc-1.0
    

    to see the output of any fmt.Print*s.

    Just in case someone is unfamiliar, you can view your containers with docker ps and the chaincode container is created after you install a chaincode and run instantiate on a new chaincode or upgrade an existing one (this creates a new container, hence the version in the container name above).

    点赞 评论 复制链接分享

相关推荐