use kmip_protocol::client::Client; use kmip_protocol::types::traits::ReadWrite; use log::error; use crate::config::Opt; pub(crate) fn init_logging(opt: &Opt) { let level = match (opt.quiet, opt.verbose) { (true, _) => log::LevelFilter::Error, (false, 1) => log::LevelFilter::Debug, (false, n) if n >= 2 => log::LevelFilter::Trace, _ => log::LevelFilter::Info, }; simple_logging::log_to_stderr(level); } pub(crate) trait ToCsvString { fn to_csv_string(self) -> String; } impl ToCsvString for Option> where T: ToString, { fn to_csv_string(self) -> String { self.unwrap_or(Vec::new()) .iter() .map(|op| op.to_string()) .collect::>() .join(", ") } } pub(crate) trait SelfLoggingError { fn log_error(self, client: &Client) -> Self; } impl SelfLoggingError for kmip_protocol::client::Result { fn log_error(self, client: &Client) -> Self { if let Err(err) = &self { error!( "{}: [req: {:?}, res: {:?}]", err, client.last_req_diag_str(), client.last_res_diag_str() ); } self } }