2 unstable releases

0.2.0 Jul 4, 2023
0.1.0 May 10, 2023

#43 in #circular-buffer

Download history 3231/week @ 2024-07-20 2890/week @ 2024-07-27 4005/week @ 2024-08-03 3252/week @ 2024-08-10 3796/week @ 2024-08-17 3356/week @ 2024-08-24 3233/week @ 2024-08-31 2923/week @ 2024-09-07 2765/week @ 2024-09-14 2884/week @ 2024-09-21 3324/week @ 2024-09-28 3150/week @ 2024-10-05 2967/week @ 2024-10-12 3080/week @ 2024-10-19 3559/week @ 2024-10-26 3333/week @ 2024-11-02

13,603 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.3–1MB
~21K SLoC