【发布时间】:2018-03-15 00:20:33
【问题描述】:
您能否给我一些关于如何在 Corda 合同中添加应用程序日志的指示。
corda 文档中有一个关于日志的页面,但它没有提供正确的示例。 https://docs.corda.net/node-administration.html?highlight=logs
您还可以帮助了解如何在 shell 控制台上打印调试语句。 这些信息将非常有用。
谢谢。
【问题讨论】:
标签: corda
您能否给我一些关于如何在 Corda 合同中添加应用程序日志的指示。
corda 文档中有一个关于日志的页面,但它没有提供正确的示例。 https://docs.corda.net/node-administration.html?highlight=logs
您还可以帮助了解如何在 shell 控制台上打印调试语句。 这些信息将非常有用。
谢谢。
【问题讨论】:
标签: corda
您按如下方式在流中执行日志记录:
@InitiatingFlow
@StartableByRPC
public static class Initiator extends FlowLogic<Void> {
@Suspendable
@Override public Void call() {
getLogger().info("Logging within a flow.");
return null;
}
}
在 Kotlin 中,这变成:
@InitiatingFlow
@StartableByRPC
class Initiator : FlowLogic<Unit>() {
@Suspendable
override fun call() {
logger.info("Logging within a flow.")
}
}
合约内的日志记录只能用于调试目的。在生产中,合同验证将在不允许记录的新交所飞地内进行。您在合同中按如下方式执行日志记录:
public class TemplateContract implements Contract {
@Override
public void verify(LedgerTransaction tx) {
LoggerFactory.getLogger(TemplateContract.class).info("Logging within a contract.");
}
}
在 Kotlin 中,您还可以使用 loggerFor 扩展函数在合约中执行日志记录:
open class TemplateContract : Contract {
override fun verify(tx: LedgerTransaction) {
loggerFor<TemplateContract>().info("Logging within a contract.")
}
}
您无法登录到节点外壳,因为外壳实际上是通过 RPC 与节点通信的远程进程。
【讨论】: