From 3664e1ea0d42985bd88129cfd338bacff2456398 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Wed, 3 Aug 2022 18:14:41 +0200 Subject: [PATCH] aya-log, test: Switch from simplelog to env_logger Signed-off-by: Michal Rostecki --- aya-log/Cargo.toml | 2 +- aya-log/README.md | 16 +++------------- aya-log/src/lib.rs | 18 ++++-------------- test/integration-test/Cargo.toml | 2 +- test/integration-test/src/main.rs | 11 +---------- 5 files changed, 10 insertions(+), 39 deletions(-) diff --git a/aya-log/Cargo.toml b/aya-log/Cargo.toml index 701f3adb..9f3f5a27 100644 --- a/aya-log/Cargo.toml +++ b/aya-log/Cargo.toml @@ -20,7 +20,7 @@ bytes = "1.1" tokio = { version = "1.2.0" } [dev-dependencies] -simplelog = "0.12" +env_logger = "0.9" testing_logger = "0.1.1" [lib] diff --git a/aya-log/README.md b/aya-log/README.md index 5e1245ca..b1af3d71 100644 --- a/aya-log/README.md +++ b/aya-log/README.md @@ -27,25 +27,15 @@ aya-log-ebpf = { git = "https://github.com/aya-rs/aya-log", branch = "main" } ## Example -Here's an example that uses `aya-log` in conjunction with the [simplelog] crate +Here's an example that uses `aya-log` in conjunction with the [env_logger] crate to log eBPF messages to the terminal. ### User space code ```rust -use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode}; use aya_log::BpfLogger; -TermLogger::init( - LevelFilter::Debug, - ConfigBuilder::new() - .set_target_level(LevelFilter::Error) - .set_location_level(LevelFilter::Error) - .build(), - TerminalMode::Mixed, - ColorChoice::Auto, -) -.unwrap(); +env_logger::init(); // Will log using the default logger, which is TermLogger in this case BpfLogger::init(&mut bpf).unwrap(); @@ -70,4 +60,4 @@ fn try_xdp_firewall(ctx: XdpContext) -> Result { [aya]: https://github.com/aya-rs/aya [log]: https://docs.rs/log -[simplelog]: https://docs.rs/simplelog +[env_logger]: https://docs.rs/env_logger diff --git a/aya-log/src/lib.rs b/aya-log/src/lib.rs index 5bdf8a9a..5b85c667 100644 --- a/aya-log/src/lib.rs +++ b/aya-log/src/lib.rs @@ -9,24 +9,14 @@ //! //! # Example: //! -//! This example uses the [simplelog] crate to log messages to the terminal. +//! This example uses the [env_logger] crate to log messages to the terminal. //! //! ```no_run //! # let mut bpf = aya::Bpf::load(&[]).unwrap(); -//! 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(); +//! // 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(); @@ -55,7 +45,7 @@ //! ``` //! //! [Aya]: https://docs.rs/aya -//! [simplelog]: https://docs.rs/simplelog +//! [env_logger]: https://docs.rs/env_logger //! [Log]: https://docs.rs/log/0.4.14/log/trait.Log.html //! [log]: https://docs.rs/log //! diff --git a/test/integration-test/Cargo.toml b/test/integration-test/Cargo.toml index decae299..fd635d3a 100644 --- a/test/integration-test/Cargo.toml +++ b/test/integration-test/Cargo.toml @@ -14,4 +14,4 @@ libc = { version = "0.2.105" } log = "0.4" object = { version = "0.29", default-features = false, features = ["std", "read_core", "elf"] } regex = "1" -simplelog = "0.12" +env_logger = "0.9" diff --git a/test/integration-test/src/main.rs b/test/integration-test/src/main.rs index f3f61b3a..a9f142b1 100644 --- a/test/integration-test/src/main.rs +++ b/test/integration-test/src/main.rs @@ -1,19 +1,10 @@ use log::info; -use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode}; mod tests; use tests::IntegrationTest; fn main() -> anyhow::Result<()> { - TermLogger::init( - LevelFilter::Debug, - ConfigBuilder::new() - .set_target_level(LevelFilter::Error) - .set_location_level(LevelFilter::Error) - .build(), - TerminalMode::Mixed, - ColorChoice::Auto, - )?; + env_logger::init(); // Run the tests for t in inventory::iter:: {