1 unstable release
new 0.1.0 | Apr 29, 2025 |
---|
#123 in #cfg
29KB
516 lines
Crate canlog
See the crate documentation.
lib.rs
:
This crate extends ic_canister_log
to provide native support for log priority levels,
filtering and sorting.
The main functionality is provided by the LogPriorityLevels
and GetLogFilter
traits
as well as the [log
] macro.
Custom log priority levels may be defined by declaring an enum and implementing the
LogPriorityLevels
trait for it, usually through the derive
annotation available with
the derive
feature of canlog
.
Additionally, log filtering may be achieved by implementing the GetLogFilter
trait on
the enum defining the log priorities.
- Example:
use canlog::{GetLogFilter, LogFilter, LogPriorityLevels, log};
#[derive(LogPriorityLevels)]
enum LogPriority {
#[log_level(capacity = 100, name = "INFO")]
Info,
#[log_level(capacity = 500, name = "DEBUG")]
Debug,
}
impl GetLogFilter for LogPriority {
fn get_log_filter() -> LogFilter {
LogFilter::ShowAll
}
}
fn main() {
log!(LogPriority::Info, "Some rather important message.");
log!(LogPriority::Debug, "Some less important message.");
}
Expected Output:
2025-02-26 08:27:10 UTC: [Canister lxzze-o7777-77777-aaaaa-cai] INFO main.rs:13 Some rather important message.
2025-02-26 08:27:10 UTC: [Canister lxzze-o7777-77777-aaaaa-cai] DEBUG main.rs:14 Some less important message.
Dependencies
~4–13MB
~141K SLoC