ic-canister-log

Crates.ioic-canister-log
lib.rsic-canister-log
version0.2.0
sourcesrc
created_at2023-05-10 12:02:59.421893
updated_at2023-07-04 13:38:40.912261
descriptionA logging library for smart contracts running on the Internet Computer.
homepage
repositoryhttps://github.com/dfinity/ic
max_upload_size
id861294
size19,395
Bas van Dijk (basvandijk)

documentation

https://docs.rs/ic-canister-log

README

IC Canister Log

This package provides a basic logging library for smart contracts running on the Internet Computer (also known as canisters).

Usage

Macros declare_log_buffer and log are the core library interface. The declare_log_buffer macros creates a circular buffer of messages with the specified capacity. The log macro formats and appends messages to a buffer.

You can extract messages from the log buffer using the export function.

use ic_canister_log::{declare_log_buffer, export, log};

// Keep up to 100 last messages.
declare_log_buffer!(name = LOG, capacity = 100);

fn sum_and_log(x: u64, y: u64) -> u64 {
   let result = x.saturating_add(y);
   log!(LOG, "{} + {} = {}", x, y, result);
   result
}

fn print_log_entries() {
  for entry in export(&LOG) {
    println!("{}:{} {}", entry.file, entry.line, entry.message);
  }
}
Commit count: 29727

cargo fmt