hyperledger - 如何控制资产中的日志值?在超级账本作曲家中?
问题描述
我正在通过超级账本作曲家游乐场编写网络。
在这里,我有一个名为patient的资产,而patient有医院列表,我有一个名为GetPatientHospitals的事务,用于调用函数getPatientHospitals,我希望这个函数打印出一个 ID 列表(例如resource:org. acme.patientchain.PatientHospital#5wyjftthjr当我测试时),但是当我测试我的功能时,它只告诉我我的交易已经提交,我看不到输出,有什么办法吗?或者我需要其他资产来存储这些消息?
我的 getPatientHospitals函数:
function getPatientHospitals(gethospitals){
return getAssetRegistry('org.acme.patientchain.Patient')
.then(function (PatientAssetRegistry) {
// Get the patient asset
return PatientAssetRegistry.get(gethospitals.patient.pubKeyPatient);
})
.then(function (patienthospital) {
return patienthospital.hospitals;
})
} //list of hospitals
我的GetPatientHospitals交易和患者资产:
transaction GetPatientHospitals {
--> Patient patient
}
asset Patient identified by pubKeyPatient {
o String pubKeyPatient
--> PatientHospital[] hospitals
}
这是我测试的一名患者的医院:
{
"$class": "org.acme.patientchain.Patient",
"pubKeyPatient": "1652",
"hospitals": [
"resource:org.acme.patientchain.PatientHospital#5wyjftthjr",
"resource:org.acme.patientchain.PatientHospital#mgnl6ag4vh",
"resource:org.acme.patientchain.PatientHospital#5wyjftthjr"
]
}
我想打印这些资源或仅打印#之后的 id
但是我在任何地方都看不到输出,我可以在这个操场上“打印”吗?
解决方案
您可以console.log()
在 js 文件中使用。然后您可以在浏览器开发者控制台中看到输出。对于 Firefox 和 Chrome,您可以使用CTRL-SHIFT-I显示开发者控制台。这仅在您使用带有“Web”配置文件的 Playground 时才有效,然后您将在浏览器控制台中看到 console.log 输出。如果您使用连接到本地 Fabric 实例的 Playground,则 console.log 输出将在 Chaincode 容器的日志中。
尝试使用console.log(patienthospital.hospitals)
并检查开发人员控制台中的输出。
推荐阅读
- c# - 获取 ConcurrentDictionary 中的 ConcurrentBag 项数
- node.js - date-fns-tz 在 IE11 上工作,是否有任何替代 date-time-format-timezone polyfill 的方法?
- apache-beam - 是否可以使用 Apache Beam JdbcIO.Write 获取生成的密钥?
- python - Python - 如何将所有行分组为一,保留所有列
- r - 混淆矩阵中的“具有相同水平的因素”
- c# - 如何使用 HttpClient 处理自定义令牌身份验证
- scala - 在 Gatling 中运行录制的模拟时,我得到了 file not found 错误
- python - 每秒更新一个小部件pyqt5
- sql - 如何使用Oracle SQL按升序分配金额
- mysql - 使用 MySQL 数据库设置 Keycloak