如何从Hyperledger Fabric链码打印和查看日志 [英] How to print and view logs from Hyperledger Fabric chaincode
问题描述
出于调试目的,我希望在调用链代码中的函数时看到日志.我尝试过这样的事情:
I want to see logs while calling functions in my chaincode, for debugging purposes. I tried something like this:
var logger = shim.NewLogger("chaincode_example02")
logger.Info("get_caller_data called");
我已经查看了运行链码的对等方的日志,但是找不到上述日志.我究竟做错了什么?
I've viewed logs of the peer running the chaincode, but I couldn't find the above log. What am I doing wrong?
推荐答案
如果使用诸如./chaincode_example02
之类的命令在开发模式下启动链码,则日志语句应在启动相同进程的控制台中可见.
If you startup your chaincode in dev mode using a command like ./chaincode_example02
, then the log statements should be visible in the console where that same process is started.
如果以网络模式部署链码,则每个对等方都会启动一个名为<networkId>-<peer enroll id>-<chaincode Id>
之类的docker容器.您可以使用命令docker ps
查看在对等方上启动的所有docker容器,并查看使用命令docker logs <container id (get this from the previous command)>
If you deploy the chaincode in net mode then each peer starts up a docker container that is named something like <networkId>-<peer enroll id>-<chaincode Id>
.You can view all the docker containers started up on a peer by using the command docker ps
, and view the content of a log by using the command docker logs <container id (get this from the previous command)>
这篇关于如何从Hyperledger Fabric链码打印和查看日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!