summaryrefslogtreecommitdiff
path: root/rust-src/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust-src/src')
-rw-r--r--rust-src/src/cmd_list.rs3
-rw-r--r--rust-src/src/cmd_mount.rs19
-rw-r--r--rust-src/src/key.rs3
-rw-r--r--rust-src/src/lib.rs1
-rw-r--r--rust-src/src/logger.rs28
5 files changed, 47 insertions, 7 deletions
diff --git a/rust-src/src/cmd_list.rs b/rust-src/src/cmd_list.rs
index f04efa2c..2dc8d719 100644
--- a/rust-src/src/cmd_list.rs
+++ b/rust-src/src/cmd_list.rs
@@ -1,5 +1,5 @@
use atty::Stream;
-use bch_bindgen::error;
+use log::{error};
use bch_bindgen::bcachefs;
use bch_bindgen::opt_set;
use bch_bindgen::fs::Fs;
@@ -9,7 +9,6 @@ use bch_bindgen::btree::BtreeIter;
use bch_bindgen::btree::BtreeNodeIter;
use bch_bindgen::btree::BtreeIterFlags;
use clap::Parser;
-use colored::Colorize;
use std::ffi::{CStr, OsStr, c_int, c_char};
use std::os::unix::ffi::OsStrExt;
diff --git a/rust-src/src/cmd_mount.rs b/rust-src/src/cmd_mount.rs
index 1251d0d7..af370ef6 100644
--- a/rust-src/src/cmd_mount.rs
+++ b/rust-src/src/cmd_mount.rs
@@ -1,11 +1,13 @@
use atty::Stream;
-use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle, debug, error, info};
+use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle};
+use log::{info, warn, debug, error, trace, LevelFilter};
use clap::Parser;
-use colored::Colorize;
use uuid::Uuid;
+use std::convert::TryInto;
use std::path::PathBuf;
use crate::key;
use crate::key::KeyLoc;
+use crate::logger::SimpleLogger;
use std::ffi::{CStr, CString, OsStr, c_int, c_char, c_void};
use std::os::unix::ffi::OsStrExt;
@@ -202,9 +204,20 @@ pub extern "C" fn cmd_mount(argc: c_int, argv: *const *const c_char) {
.collect();
let opt = Cli::parse_from(argv);
- bch_bindgen::log::set_verbose_level(opt.verbose + bch_bindgen::log::ERROR);
+
+ log::set_boxed_logger(Box::new(SimpleLogger)).unwrap();
+
+ // @TODO : more granular log levels via mount option
+ log::set_max_level(match opt.verbose {
+ 0 => LevelFilter::Warn,
+ 1 => LevelFilter::Trace,
+ 2_u8..=u8::MAX => todo!(),
+ });
+
colored::control::set_override(opt.colorize);
if let Err(e) = cmd_mount_inner(opt) {
error!("Fatal error: {}", e);
+ } else {
+ info!("Successfully mounted");
}
}
diff --git a/rust-src/src/key.rs b/rust-src/src/key.rs
index abea5844..2af34b13 100644
--- a/rust-src/src/key.rs
+++ b/rust-src/src/key.rs
@@ -1,6 +1,5 @@
-use bch_bindgen::info;
+use log::{info};
use bch_bindgen::bcachefs::bch_sb_handle;
-use colored::Colorize;
use crate::c_str;
use anyhow::anyhow;
diff --git a/rust-src/src/lib.rs b/rust-src/src/lib.rs
index a33e3914..159d049d 100644
--- a/rust-src/src/lib.rs
+++ b/rust-src/src/lib.rs
@@ -1,4 +1,5 @@
pub mod key;
+pub mod logger;
pub mod cmd_mount;
pub mod cmd_list;
diff --git a/rust-src/src/logger.rs b/rust-src/src/logger.rs
new file mode 100644
index 00000000..2cd7b363
--- /dev/null
+++ b/rust-src/src/logger.rs
@@ -0,0 +1,28 @@
+use colored::Colorize;
+use log::{Level, Metadata, Record};
+
+pub struct SimpleLogger;
+
+impl log::Log for SimpleLogger {
+ fn enabled(&self, _: &Metadata) -> bool {
+ true
+ }
+
+ fn log(&self, record: &Record) {
+ let debug_prefix = match record.level() {
+ Level::Error => "ERROR".bright_red(),
+ Level::Warn => "WARN".bright_yellow(),
+ Level::Info => "INFO".green(),
+ Level::Debug => "DEBUG".bright_blue(),
+ Level::Trace => "TRACE".into(),
+ };
+ println!(
+ "{} - {}: {}",
+ debug_prefix,
+ record.module_path().unwrap_or_default().bright_black(),
+ record.args()
+ );
+ }
+
+ fn flush(&self) {}
+}