diff options
author | TruongSinh Tran-Nguyen <i@truongsinh.pro> | 2023-04-26 12:50:16 -0700 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-04-26 17:46:23 -0400 |
commit | 47ec3ed6edb90c1117d0c79c382f03a3ed87c5ca (patch) | |
tree | 2aae100d0d553104b8276e8785865a7fc7b84991 /rust-src/bch_bindgen | |
parent | 4f6b28f54f09ee4498466d39cf550faeedd5614a (diff) |
chore: logger for idiomatic style and expanded logging levels
Improve the Rust logger by adhering to idiomatic Rust conventions and
incorporating additional logging levels: warn, debug, and trace.
Signed-off-by: TruongSinh Tran-Nguyen <i@truongsinh.pro>
Diffstat (limited to 'rust-src/bch_bindgen')
-rw-r--r-- | rust-src/bch_bindgen/src/lib.rs | 1 | ||||
-rw-r--r-- | rust-src/bch_bindgen/src/log.rs | 57 |
2 files changed, 0 insertions, 58 deletions
diff --git a/rust-src/bch_bindgen/src/lib.rs b/rust-src/bch_bindgen/src/lib.rs index 86592c6b..73aeef64 100644 --- a/rust-src/bch_bindgen/src/lib.rs +++ b/rust-src/bch_bindgen/src/lib.rs @@ -3,7 +3,6 @@ pub mod btree; pub mod bkey; pub mod errcode; pub mod keyutils; -pub mod log; pub mod rs; pub mod fs; pub mod opts; diff --git a/rust-src/bch_bindgen/src/log.rs b/rust-src/bch_bindgen/src/log.rs deleted file mode 100644 index 32927f16..00000000 --- a/rust-src/bch_bindgen/src/log.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::sync::atomic::{AtomicU8, Ordering}; - -pub const MUTE: u8 = 0; -pub const ERROR: u8 = 1; -pub const INFO: u8 = 2; -pub const DEBUG: u8 = 3; - -// error level by default -pub static VERBOSE: AtomicU8 = AtomicU8::new(ERROR); - -#[inline] -pub fn set_verbose_level(level: u8) { - VERBOSE.store(level, Ordering::SeqCst); -} - -pub fn max_level() -> u8 { - VERBOSE.load(Ordering::SeqCst) -} - -#[macro_export] -macro_rules! info { - ($($arg:tt)*) => { - if 2 <= $crate::log::max_level() { - println!("{} {} {}", - " INFO".green(), - format!("{}:", module_path!()).bright_black(), - format_args!($($arg)*) - ); - } - } -} - -#[macro_export] -macro_rules! debug { - ($($arg:tt)*) => { - if 3 <= $crate::log::max_level() { - println!("{} {} {}", - "DEBUG".bright_blue(), - format!("{}:", module_path!()).bright_black(), - format_args!($($arg)*) - ); - } - } -} - -#[macro_export] -macro_rules! error { - ($($arg:tt)*) => { - if 1 <= $crate::log::max_level() { - println!("{} {} {}", - "ERROR".bright_red(), - format!("{}:", module_path!()).bright_black(), - format_args!($($arg)*) - ); - } - } -} |