Expand description
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.Macros§
- declare_
log_ buffer - Declares a new canister log buffer.
- log
- Wrapper for the
ic_canister_log::logmacro that allows logging for a given variant of an enum implementing theLogPriorityLevelstrait. See the example in the crate documentation. - raw_log
- Adds a new record to a canister log buffer.
Structs§
- Log
- A container for log entries at a given log priority level.
- LogEntry
- A single log entry.
- Regex
String - A string used as a regex pattern.
- Regex
Substitution - A regex-based substitution with a pattern and replacement string.
Enums§
- LogFilter
- Only log entries matching this filter will be recorded.
- Sort
- Defines a sorting order for log entries
Traits§
- GetLog
Filter - Returns the
LogFilterto check what entries to record. This trait should be implemented manually. - LogPriority
Levels - Represents a log priority level. This trait is meant to be implemented
automatically with the
deriveattribute macro which is available with thederivefeature of this crate. - Sink
Functions§
- export_
logs - Exports the contents of a buffer as a vector of entries in the order of insertion.