feat(aya-log): Rename BpfLogger to EbpfLogger

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/528/head
Dave Tucker 7 months ago
parent cf3e2ca677
commit a93e354620

@ -33,12 +33,12 @@ to log eBPF messages to the terminal.
### User space code ### User space code
```rust ```rust
use aya_log::BpfLogger; use aya_log::EbpfLogger;
env_logger::init(); env_logger::init();
// Will log using the default logger, which is TermLogger in this case // Will log using the default logger, which is TermLogger in this case
BpfLogger::init(&mut bpf).unwrap(); EbpfLogger::init(&mut bpf).unwrap();
``` ```
### eBPF code ### eBPF code

@ -3,7 +3,7 @@
//! This is the user space side of the [Aya] logging framework. For the eBPF //! This is the user space side of the [Aya] logging framework. For the eBPF
//! side, see the `aya-log-ebpf` crate. //! 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 //! `aya-log-ebpf` and logs them using the [log] crate. Any logger that
//! implements the [Log] trait can be used with this crate. //! implements the [Log] trait can be used with this crate.
//! //!
@ -13,13 +13,13 @@
//! //!
//! ```no_run //! ```no_run
//! # let mut bpf = aya::Bpf::load(&[]).unwrap(); //! # let mut bpf = aya::Bpf::load(&[]).unwrap();
//! use aya_log::BpfLogger; //! use aya_log::EbpfLogger;
//! //!
//! // initialize env_logger as the default logger //! // initialize env_logger as the default logger
//! env_logger::init(); //! env_logger::init();
//! //!
//! // start reading aya-log records and log them using the default logger //! // 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: //! 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. /// Log messages generated by `aya_log_ebpf` using the [log] crate.
/// ///
/// For more details see the [module level documentation](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 /// Starts reading log records created with `aya-log-ebpf` and logs them
/// with the default logger. See [log::logger]. /// with the default logger. See [log::logger].
pub fn init(bpf: &mut Bpf) -> Result<BpfLogger, Error> { pub fn init(bpf: &mut Bpf) -> Result<EbpfLogger, Error> {
BpfLogger::init_with_logger(bpf, log::logger()) EbpfLogger::init_with_logger(bpf, log::logger())
} }
/// Starts reading log records created with `aya-log-ebpf` and logs them /// 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>( pub fn init_with_logger<T: Log + 'static>(
bpf: &mut Bpf, bpf: &mut Bpf,
logger: T, logger: T,
) -> Result<BpfLogger, Error> { ) -> Result<EbpfLogger, Error> {
let logger = Arc::new(logger); let logger = Arc::new(logger);
let mut logs: AsyncPerfEventArray<_> = bpf let mut logs: AsyncPerfEventArray<_> = bpf
.take_map(MAP_NAME) .take_map(MAP_NAME)
@ -131,7 +135,7 @@ impl BpfLogger {
}); });
} }
Ok(BpfLogger {}) Ok(EbpfLogger {})
} }
} }

@ -4,7 +4,7 @@ use std::{
}; };
use aya::{programs::UProbe, Bpf}; use aya::{programs::UProbe, Bpf};
use aya_log::BpfLogger; use aya_log::EbpfLogger;
use log::{Level, Log, Record}; use log::{Level, Log, Record};
use test_log::test; use test_log::test;
@ -45,7 +45,7 @@ async fn log() {
let captured_logs = Arc::new(Mutex::new(Vec::new())); let captured_logs = Arc::new(Mutex::new(Vec::new()));
{ {
let captured_logs = captured_logs.clone(); let captured_logs = captured_logs.clone();
BpfLogger::init_with_logger( EbpfLogger::init_with_logger(
&mut bpf, &mut bpf,
TestingLogger { TestingLogger {
log: move |record: &Record| { log: move |record: &Record| {

Loading…
Cancel
Save