Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libbpf-cargo: Add proper logging infrastructure
We support a very limited form of logging by printing certain actions happening when the --debug option is provided. While not particularly useful at the current stage, this is probably functionality worth keeping in the long run. However, the current implementation is questionable at best: we plumb through some boolean flag everywhere, which convolutes various call sites and requires potentially excessive changes to support emitting a new log message somewhere. With this change we switch over to using proper logging based on the log crate and other parts of the ecosystem. As a result, we get support for multiple log levels, proper time stamping, limited output coloring, and additional filtering capabilities via environment variables. At the same time, we remove usage of flags that have to be plumbed through everywhere, because logging state is global state. Before: $ cargo run -- libbpf build --manifest-path libbpf-rs/examples/capable/Cargo.toml --clang-args='-I~/.cargo/git/checkouts/vmlinux.h-ec81e0afb9d5f7e2/83a228/include/x86/' --debug > Metadata for package=libbpf-cargo > null > Metadata for package=libbpf-rs > null After: $ cargo run -- libbpf build --manifest-path libbpf-rs/examples/capable/Cargo.toml --clang-args='-I~/.cargo/git/checkouts/vmlinux.h-ec81e0afb9d5f7e2/83a228/include/x86/' -vvv > [2025-01-16T17:10:44Z DEBUG libbpf_cargo::metadata] Metadata for package=libbpf-cargo > [2025-01-16T17:10:44Z DEBUG libbpf_cargo::metadata] null > [2025-01-16T17:10:44Z DEBUG libbpf_cargo::metadata] Metadata for package=libbpf-rs > [2025-01-16T17:10:44Z DEBUG libbpf_cargo::metadata] null For tests, usage is simple as well: $ RUST_LOG=trace cargo test -- test::test_make_basic --nocapture > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::metadata] Metadata for package=proj > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::metadata] null > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::build] Found bpf progs to compile: > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::build] UnprocessedObj { package: "proj", path: "/tmp/.tmpXhQPS6/proj/src/bpf/prog.bpf.c", out: "/tmp/.tmpXhQPS6/proj/target/bpf", name: "prog" } > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::build] Building /tmp/.tmpXhQPS6/proj/src/bpf/prog.bpf.c > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::metadata] Metadata for package=proj > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::metadata] null > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::gen] Found bpf objs to gen skel: > [2025-01-16T17:17:46Z DEBUG libbpf_cargo::gen] UnprocessedObj { package: "proj", path: "/tmp/.tmpXhQPS6/proj/src/bpf/prog.bpf.c", out: "/tmp/.tmpXhQPS6/proj/target/bpf", name: "prog" } > test test::test_make_basic ... ok Signed-off-by: Daniel Müller <[email protected]>
- Loading branch information