scx_utils/libbpf_logger.rs
1// Copyright (c) Meta Platforms, Inc. and affiliates.
2//
3// This software may be used and distributed according to the terms of the
4// GNU General Public License version 2.
5
6use libbpf_rs::{PrintLevel, set_print};
7
8fn print_to_log(level: PrintLevel, msg: String) {
9 match level {
10 PrintLevel::Debug => log::debug!("{}", msg),
11 PrintLevel::Info => log::info!("{}", msg),
12 PrintLevel::Warn => log::warn!("{}", msg),
13 }
14}
15
16pub fn init_libbpf_logging(level: Option<PrintLevel>) {
17 set_print(Some((level.unwrap_or(PrintLevel::Debug), print_to_log)));
18}