Low Level Logging in Solidity

Low Level Logging in Solidity

Solidity does provide low level logging mechanism which developer can use to log the message. Events are most commonly used when we need to perform logging and need interaction through web3 but this blog talk about low level logging option in solidity.

As shown in diagram below, you can use log function to perform at low level.

General syntax for these logging statement is below where i is any positive integer value.

logi(data, topic)

Low Level Logging in Solidity

Low Level Logging in Solidity

 

Here every log function accept only data field as input and that should be first parameter and rest other parameters are topics (equivalent to Id field).

When you use log1 , then you need to have two argument to that log function so in general logi function will have i+1 argument and first argument will be always be a data.

Below is the example smart contract that show how it work.

pragma solidity ^0.4.20;

contract lowLevelLogging{
bytes32 public result;
function setResult(bytes32 _input) public returns(bytes32){
result=_input;
log2(bytes32(_input),bytes32(0x240012), bytes32(0x240013));
return result;
}
}

Below diagram show how log looks like when we use log statement in the smart contract.

Low Level Logging in Solidity Example

Low Level Logging in Solidity Example

 

No Comments

Post a Reply

Inquire Now
close slider