ic-logger

Crates.ioic-logger
lib.rsic-logger
version0.1.0
sourcesrc
created_at2023-07-27 23:59:45.271479
updated_at2023-07-27 23:59:45.271479
descriptionA logger for the Internet Computer
homepagehttps://github.com/zvolin/ic-logger
repositoryhttps://github.com/zvolin/ic-logger
max_upload_size
id928034
size29,529
Maciej ZwoliƄski (zvolin)

documentation

https://docs.rs/ic-logger

README

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.

Commit count: 209

cargo fmt