ic-logger 0.1.0

A logger for the Internet Computer
Documentation
  • Coverage
  • 66.67%
    8 out of 12 items documented3 out of 8 items with examples
  • Size
  • Source code size: 29.03 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 482.38 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 40s Average build duration of successful builds.
  • all releases: 40s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • zvolin/ic-logger
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zvolin

ic-logger

A simple logging backend for ICP canisters.

Usage

use ic_cdk::{init, query};

mod foo {
    pub fn bar() {
        log::warn!("sample log");
    }
}

#[init]
async fn init() {
    ic_cdk::setup();
}

#[update]
async fn baz() -> Result<()> {
    let _ = ic_logger::init();

    foo::bar();
}

This outputs:

2023-07-27 23:08:09.718590904 UTC: [Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] [WARN  my_canister::foo] sample log

You can run the above example with:

dfx start --clean --background
dfx deploy
dfx call my_canister baz

As the canister's flexible memory may be dropped, it's suggested to call ic_logger::init() (or equivalent) in each canister function and drop the result in case the logger was already initialized.

Licence

ic-logger is licenced under the MIT Licence.

Credits

Forked from simple_logger written by Sam Clements.