|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
//! 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` provides the [EbpfLogger] 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.
|
|
|
|
|
//!
|
|
|
|
@ -13,13 +13,13 @@
|
|
|
|
|
//!
|
|
|
|
|
//! ```no_run
|
|
|
|
|
//! # let mut bpf = aya::Bpf::load(&[]).unwrap();
|
|
|
|
|
//! use aya_log::BpfLogger;
|
|
|
|
|
//! use aya_log::EbpfLogger;
|
|
|
|
|
//!
|
|
|
|
|
//! // initialize env_logger as the default logger
|
|
|
|
|
//! env_logger::init();
|
|
|
|
|
//!
|
|
|
|
|
//! // start reading aya-log records and log them using the default logger
|
|
|
|
|
//! BpfLogger::init(&mut bpf).unwrap();
|
|
|
|
|
//! EbpfLogger::init(&mut bpf).unwrap();
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! With the following eBPF code:
|
|
|
|
@ -93,13 +93,17 @@ unsafe impl Pod for DisplayHintWrapper {}
|
|
|
|
|
/// Log messages generated by `aya_log_ebpf` using the [log] crate.
|
|
|
|
|
///
|
|
|
|
|
/// For more details see the [module level documentation](crate).
|
|
|
|
|
pub struct BpfLogger;
|
|
|
|
|
pub struct EbpfLogger;
|
|
|
|
|
|
|
|
|
|
impl BpfLogger {
|
|
|
|
|
/// Log messages generated by `aya_log_ebpf` using the [log] crate.
|
|
|
|
|
#[deprecated(since = "0.2.1", note = "Use `aya_log::EbpfLogger` instead")]
|
|
|
|
|
pub type BpfLogger = EbpfLogger;
|
|
|
|
|
|
|
|
|
|
impl EbpfLogger {
|
|
|
|
|
/// Starts reading log records created with `aya-log-ebpf` and logs them
|
|
|
|
|
/// with the default logger. See [log::logger].
|
|
|
|
|
pub fn init(bpf: &mut Bpf) -> Result<BpfLogger, Error> {
|
|
|
|
|
BpfLogger::init_with_logger(bpf, log::logger())
|
|
|
|
|
pub fn init(bpf: &mut Bpf) -> Result<EbpfLogger, Error> {
|
|
|
|
|
EbpfLogger::init_with_logger(bpf, log::logger())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Starts reading log records created with `aya-log-ebpf` and logs them
|
|
|
|
@ -107,7 +111,7 @@ impl BpfLogger {
|
|
|
|
|
pub fn init_with_logger<T: Log + 'static>(
|
|
|
|
|
bpf: &mut Bpf,
|
|
|
|
|
logger: T,
|
|
|
|
|
) -> Result<BpfLogger, Error> {
|
|
|
|
|
) -> Result<EbpfLogger, Error> {
|
|
|
|
|
let logger = Arc::new(logger);
|
|
|
|
|
let mut logs: AsyncPerfEventArray<_> = bpf
|
|
|
|
|
.take_map(MAP_NAME)
|
|
|
|
@ -131,7 +135,7 @@ impl BpfLogger {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(BpfLogger {})
|
|
|
|
|
Ok(EbpfLogger {})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|