Logging

Logging is a way to record data as the program runs.

The standard library provides a logging module which contains a generic log function that is used to log a variable of any type.

Each call to log appends 1 of 2 types of a receipt to the list of receipts

  • Log
    • Generated for non-reference types: bool, u8, u16, u32, and u64
  • LogData
    • Generated for reference types and u256

The Rust & Typescript SDKs may be used to decode the data.

Example

To use the log function we must import it from the standard library and pass in any generic type T that we want to log.

fn log_data(number: u64) {
    // generic T = `number` of type `u64`
    log(number);
}

In the example above a u64 is used however we can pass in any generic type such as a struct, enum, string etc.