Crates.io | ic-logger |
lib.rs | ic-logger |
version | 0.1.0 |
source | src |
created_at | 2023-07-27 23:59:45.271479 |
updated_at | 2023-07-27 23:59:45.271479 |
description | A logger for the Internet Computer |
homepage | https://github.com/zvolin/ic-logger |
repository | https://github.com/zvolin/ic-logger |
max_upload_size | |
id | 928034 |
size | 29,529 |
A simple logging backend for ICP canisters.
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.
ic-logger
is licenced under the MIT Licence.
Forked from simple_logger written by Sam Clements.