corda合同的应用程序日志记录

时间:2018-03-14 13:44:44

标签: corda

请您给我一些指示,如何在corda合同中添加应用程序日志。

有关日志的corda文档中有一个页面,但它没有提供正确的示例。 https://docs.corda.net/node-administration.html?highlight=logs

另外,您可以帮助了解如何在shell控制台上打印调试语句。 这些信息非常有用。

谢谢。

1 个答案:

答案 0 :(得分:3)

您可以按如下方式在流中执行记录:

@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.")
    }
}

只应出于调试目的执行合同中的记录。在生产中,合同验证将在SGX飞地内进行,不允许采伐。您可以按如下方式在合同中执行记录:

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.")
    }
}

您无法登录到节点shell,因为shell实际上是通过RPC与节点通信的远程进程。