Unable to print to logs in Hyperledger chaincode

2019-07-10 04:07发布

问题:

Why am I not able to see output of any of the "fmt.Println" or "fmt.Printf" statements specified in the chaincode in the logs even when the logging level is set to "DEBUG"?

I am using pre-built docker images to start a hyperledger node in Ubuntu.

回答1:

Most likely that is happening because you are trying to find your messages in a log stream which is generated by peer server. But chaincode is executed in independent docker container and has it's own log stream.

In order to get an access to the chaincode's logs, on the same server where peer process is started, right after chaincode is deployed:

  1. Tun command docker ps. The output should looks like:

    77636df123e3        dev-jdoe-1edd7(...YOUR CHAINCODE  ID)
    
  2. Then attach to docker container where your chaincode is exectued using docker attach 77636df123e3

  3. Execute any of your chaincode's methods and check if log messages appears in this stream



回答2:

some things like this:

docker logs dev-peer1.org2.example.com-mycc-1.0