This is an experimental feature for Truffle that introduces a console.log
-equivalent in your Solidity smart contracts.
Please leave your feedback in this issue: trufflesuite#3
Simply import the Console library:
import "truffle/Console.sol";
And just log out your variables with Console.log
like this!
Console.log(myBool);
Console.log(myInt);
Console.log(myUint);
Console.log(myString);
Console.log(myBytes32);
Console.log(myAddress);
You can also pass in a label for your variable so it's easier to track:
Console.log("This is myBool", myBool);
Console.log("This is myInt", myInt);
Console.log("This is myUint", myUint);
Console.log("This is myString", myString);
Console.log("This is myBytes32", myBytes32);
Console.log("This is myAddress", myAddress);
Clone this project, and then run the following steps:
-
Spawn a Truffle develop console with the
Console.log
-enhanced version of Truffle:npx truffle@truffleLogger develop
-
Run tests at the prompt:
truffle(develop)> test
-
Note the output with respect to what is logged in the smart contract.
For reference, take a look at the following files:
This is what you need to do to use the logger inside your existing Truffle projects:
-
Import the
Console
library in your contracts:import "truffle/Console.sol";
-
Call the logging function:
Console.log(myVariable);
-
Spawn a Truffle develop console with the
Console.log
-enhanced version of Truffle:npx truffle@truffleLogger develop
-
Run tests at the prompt:
truffle(develop)> test