Merge pull request #357 from vadorovsky/env_logger

aya-log, test: Switch from simplelog to env_logger
pull/359/head
Michal Rostecki 2 years ago committed by GitHub
commit 3d5ab0b17d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,7 +20,7 @@ bytes = "1.1"
tokio = { version = "1.2.0" } tokio = { version = "1.2.0" }
[dev-dependencies] [dev-dependencies]
simplelog = "0.12" env_logger = "0.9"
testing_logger = "0.1.1" testing_logger = "0.1.1"
[lib] [lib]

@ -27,25 +27,15 @@ aya-log-ebpf = { git = "https://github.com/aya-rs/aya-log", branch = "main" }
## Example ## 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. to log eBPF messages to the terminal.
### User space code ### User space code
```rust ```rust
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
use aya_log::BpfLogger; use aya_log::BpfLogger;
TermLogger::init( env_logger::init();
LevelFilter::Debug,
ConfigBuilder::new()
.set_target_level(LevelFilter::Error)
.set_location_level(LevelFilter::Error)
.build(),
TerminalMode::Mixed,
ColorChoice::Auto,
)
.unwrap();
// 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(); BpfLogger::init(&mut bpf).unwrap();
@ -70,4 +60,4 @@ fn try_xdp_firewall(ctx: XdpContext) -> Result<u32, ()> {
[aya]: https://github.com/aya-rs/aya [aya]: https://github.com/aya-rs/aya
[log]: https://docs.rs/log [log]: https://docs.rs/log
[simplelog]: https://docs.rs/simplelog [env_logger]: https://docs.rs/env_logger

@ -9,24 +9,14 @@
//! //!
//! # Example: //! # 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 //! ```no_run
//! # let mut bpf = aya::Bpf::load(&[]).unwrap(); //! # let mut bpf = aya::Bpf::load(&[]).unwrap();
//! use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
//! use aya_log::BpfLogger; //! use aya_log::BpfLogger;
//! //!
//! // initialize simplelog::TermLogger as the default logger //! // initialize env_logger as the default logger
//! TermLogger::init( //! env_logger::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 //! // start reading aya-log records and log them using the default logger
//! BpfLogger::init(&mut bpf).unwrap(); //! BpfLogger::init(&mut bpf).unwrap();
@ -55,7 +45,7 @@
//! ``` //! ```
//! //!
//! [Aya]: https://docs.rs/aya //! [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/0.4.14/log/trait.Log.html
//! [log]: https://docs.rs/log //! [log]: https://docs.rs/log
//! //!

@ -14,4 +14,4 @@ libc = { version = "0.2.105" }
log = "0.4" log = "0.4"
object = { version = "0.29", default-features = false, features = ["std", "read_core", "elf"] } object = { version = "0.29", default-features = false, features = ["std", "read_core", "elf"] }
regex = "1" regex = "1"
simplelog = "0.12" env_logger = "0.9"

@ -1,19 +1,10 @@
use log::info; use log::info;
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
mod tests; mod tests;
use tests::IntegrationTest; use tests::IntegrationTest;
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
TermLogger::init( env_logger::init();
LevelFilter::Debug,
ConfigBuilder::new()
.set_target_level(LevelFilter::Error)
.set_location_level(LevelFilter::Error)
.build(),
TerminalMode::Mixed,
ColorChoice::Auto,
)?;
// Run the tests // Run the tests
for t in inventory::iter::<IntegrationTest> { for t in inventory::iter::<IntegrationTest> {

Loading…
Cancel
Save