Expand description
A logging framework for eBPF programs.
This is the user space side of the Aya logging framework. For the eBPF
side, see the aya-log-ebpf crate.
aya-log provides the BpfLogger type, which reads log records created by
aya-log-ebpf and logs them using the log crate. Any logger that
implements the Log trait can be used with this crate.
Example:
This example uses the simplelog crate to log messages to the terminal.
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
use aya_log::BpfLogger;
// initialize simplelog::TermLogger as the default logger
TermLogger::init(
LevelFilter::Debug,
ConfigBuilder::new()
.set_target_level(LevelFilter::Error)
.set_location_level(LevelFilter::Error)
.build(),
TerminalMode::Mixed,
ColorChoice::Auto,
)
.unwrap();
// start reading aya-log records and log them using the default logger
BpfLogger::init(&mut bpf).unwrap();With the following eBPF code:
use aya_log_ebpf::{debug, error, info, trace, warn};
error!(&ctx, "this is an error message 🚨");
warn!(&ctx, "this is a warning message ⚠️");
info!(&ctx, "this is an info message ℹ️");
debug!(&ctx, "this is a debug message ️🐝");
trace!(&ctx, "this is a trace message 🔍");Outputs:
21:58:55 [ERROR] xxx: [src/main.rs:35] this is an error message 🚨
21:58:55 [WARN] xxx: [src/main.rs:36] this is a warning message ⚠️
21:58:55 [INFO] xxx: [src/main.rs:37] this is an info message ℹ️
21:58:55 [DEBUG] (7) xxx: [src/main.rs:38] this is a debug message ️🐝
21:58:55 [TRACE] (7) xxx: [src/main.rs:39] this is a trace message 🔍