#internet-computer #canister #logging #dfinity #smart-contracts #circular-buffer

ic-canister-log

A logging library for smart contracts running on the Internet Computer

2 unstable releases

0.2.0 Jul 4, 2023
0.1.0 May 10, 2023

#2676 in Magic Beans

Download history 2490/week @ 2024-01-05 2360/week @ 2024-01-12 2413/week @ 2024-01-19 2398/week @ 2024-01-26 2759/week @ 2024-02-02 3005/week @ 2024-02-09 3345/week @ 2024-02-16 2240/week @ 2024-02-23 2569/week @ 2024-03-01 3386/week @ 2024-03-08 3030/week @ 2024-03-15 2890/week @ 2024-03-22 2789/week @ 2024-03-29 2959/week @ 2024-04-05 3042/week @ 2024-04-12 2506/week @ 2024-04-19

11,846 downloads per month
Used in ic-canister-serve

Apache-2.0

9KB
130 lines

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);
  }
}

Dependencies

~0.4–1MB
~24K SLoC