Loom has built in configurable logging. The user can configure the log level and the log destination.
Loom SDK Logging
Configuring the log level
There are two types of logs in the loom sdk. The first is the logs of the blockchain transactions and the consensus events. The second is logs generated by the loom sdk, things like emitted events.
Set the following in your
loom.yaml to set logging levels.
LoomLogLevel: debug # sets log level for events emitted from the loom sdk BlockchainLogLevel: error # sets log level for the blockchain logs.
Defaults for the
Configuring the log destination
Currently a file target is supported for the loom logs.
LogDestination: "file://loom.log" # loom.log is also the default target.
To log to stderr, specify the destination as
Configurations like log level and destination are seperate for contracts. These
are set using environment variables.
CONTRACT_LOG_LEVEL=debug CONTRACT_LOG_DESTINATION="file://-" $LOOM_EXE run
This will set the contract log level to
debug and the destination to stderr.
The default for log level and destination are
Logging from the contract
The contract context has a pre-configured logger that can be used for structured logging. For example
ctx.Logger().Info("Created account", "owner", owner, "address", addr)
will generate a log line like
ts=2018-05-13T02:06:49.817229589Z module=loom level=info _msg="Created account" owner=godbole4 address="\ufffd8\ufffd\ufffd\ufffd\ufffd\ufffd$Y+H\ufffd\u0012\u000c]\u001a\ufffd\ufffd\ufffd\ufffd"
Available methods on the context logger are