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" }
[dev-dependencies]
simplelog = "0.12"
env_logger = "0.9"
testing_logger = "0.1.1"
[lib]

@ -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<u32, ()> {
[aya]: https://github.com/aya-rs/aya
[log]: https://docs.rs/log
[simplelog]: https://docs.rs/simplelog
[env_logger]: https://docs.rs/env_logger

@ -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
//!

@ -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"

@ -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::<IntegrationTest> {

Loading…
Cancel
Save