replace print with log macro

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Hannes Laimer 2022-06-15 08:19:55 +00:00 committed by Wolfgang Bumiller
parent d0c75b9b9c
commit 0608b36b30
6 changed files with 20 additions and 49 deletions

View File

@ -29,7 +29,7 @@ async fn upload_speed() -> Result<f64, Error> {
.await?; .await?;
println!("start upload speed test"); println!("start upload speed test");
let res = client.upload_speedtest(true).await?; let res = client.upload_speedtest().await?;
Ok(res) Ok(res)
} }

View File

@ -336,7 +336,6 @@ fn extract(
entries_max: ENCODER_MAX_ENTRIES, entries_max: ENCODER_MAX_ENTRIES,
device_set: None, device_set: None,
patterns, patterns,
verbose: false,
skip_lost_and_found: false, skip_lost_and_found: false,
}; };

View File

@ -12,6 +12,7 @@ path = "src/main.rs"
anyhow = "1.0" anyhow = "1.0"
futures = "0.3" futures = "0.3"
nix = "0.24" nix = "0.24"
log = "0.4"
serde_json = "1.0" serde_json = "1.0"
tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] } tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] }

View File

@ -23,7 +23,6 @@ fn extract_archive_from_reader<R: std::io::Read>(
reader: &mut R, reader: &mut R,
target: &str, target: &str,
feature_flags: Flags, feature_flags: Flags,
verbose: bool,
options: PxarExtractOptions, options: PxarExtractOptions,
) -> Result<(), Error> { ) -> Result<(), Error> {
pbs_client::pxar::extract_archive( pbs_client::pxar::extract_archive(
@ -31,9 +30,7 @@ fn extract_archive_from_reader<R: std::io::Read>(
Path::new(target), Path::new(target),
feature_flags, feature_flags,
|path| { |path| {
if verbose { log::debug!("{:?}", path);
println!("{:?}", path);
}
}, },
options, options,
) )
@ -58,11 +55,6 @@ fn extract_archive_from_reader<R: std::io::Read>(
description: "Target directory", description: "Target directory",
optional: true, optional: true,
}, },
verbose: {
description: "Verbose output.",
optional: true,
default: false,
},
"no-xattrs": { "no-xattrs": {
description: "Ignore extended file attributes.", description: "Ignore extended file attributes.",
optional: true, optional: true,
@ -116,7 +108,6 @@ fn extract_archive(
archive: String, archive: String,
pattern: Option<Vec<String>>, pattern: Option<Vec<String>>,
target: Option<String>, target: Option<String>,
verbose: bool,
no_xattrs: bool, no_xattrs: bool,
no_fcaps: bool, no_fcaps: bool,
no_acls: bool, no_acls: bool,
@ -179,7 +170,7 @@ fn extract_archive(
// otherwise we want to log them but not act on them // otherwise we want to log them but not act on them
Some(Box::new(move |err| { Some(Box::new(move |err| {
was_ok.store(false, Ordering::Release); was_ok.store(false, Ordering::Release);
eprintln!("error: {}", err); log::error!("error: {}", err);
Ok(()) Ok(())
}) })
as Box<dyn FnMut(Error) -> Result<(), Error> + Send>) as Box<dyn FnMut(Error) -> Result<(), Error> + Send>)
@ -195,14 +186,12 @@ fn extract_archive(
if archive == "-" { if archive == "-" {
let stdin = std::io::stdin(); let stdin = std::io::stdin();
let mut reader = stdin.lock(); let mut reader = stdin.lock();
extract_archive_from_reader(&mut reader, target, feature_flags, verbose, options)?; extract_archive_from_reader(&mut reader, target, feature_flags, options)?;
} else { } else {
if verbose { log::debug!("PXAR extract: {}", archive);
println!("PXAR extract: {}", archive);
}
let file = std::fs::File::open(archive)?; let file = std::fs::File::open(archive)?;
let mut reader = std::io::BufReader::new(file); let mut reader = std::io::BufReader::new(file);
extract_archive_from_reader(&mut reader, target, feature_flags, verbose, options)?; extract_archive_from_reader(&mut reader, target, feature_flags, options)?;
} }
if !was_ok.load(Ordering::Acquire) { if !was_ok.load(Ordering::Acquire) {
@ -221,11 +210,6 @@ fn extract_archive(
source: { source: {
description: "Source directory.", description: "Source directory.",
}, },
verbose: {
description: "Verbose output.",
optional: true,
default: false,
},
"no-xattrs": { "no-xattrs": {
description: "Ignore extended file attributes.", description: "Ignore extended file attributes.",
optional: true, optional: true,
@ -285,7 +269,6 @@ fn extract_archive(
async fn create_archive( async fn create_archive(
archive: String, archive: String,
source: String, source: String,
verbose: bool,
no_xattrs: bool, no_xattrs: bool,
no_fcaps: bool, no_fcaps: bool,
no_acls: bool, no_acls: bool,
@ -318,7 +301,6 @@ async fn create_archive(
entries_max: entries_max as usize, entries_max: entries_max as usize,
device_set, device_set,
patterns, patterns,
verbose,
skip_lost_and_found: false, skip_lost_and_found: false,
}; };
@ -363,9 +345,7 @@ async fn create_archive(
writer, writer,
feature_flags, feature_flags,
move |path| { move |path| {
if verbose { log::debug!("{:?}", path);
println!("{:?}", path);
}
Ok(()) Ok(())
}, },
None, None,
@ -404,9 +384,7 @@ async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Re
select! { select! {
res = session.fuse() => res?, res = session.fuse() => res?,
_ = interrupt.recv().fuse() => { _ = interrupt.recv().fuse() => {
if verbose { log::debug!("interrupted");
eprintln!("interrupted");
}
} }
} }
@ -419,23 +397,18 @@ async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Re
archive: { archive: {
description: "Archive name.", description: "Archive name.",
}, },
verbose: {
description: "Verbose output.",
optional: true,
default: false,
},
}, },
}, },
)] )]
/// List the contents of an archive. /// List the contents of an archive.
fn dump_archive(archive: String, verbose: bool) -> Result<(), Error> { fn dump_archive(archive: String) -> Result<(), Error> {
for entry in pxar::decoder::Decoder::open(archive)? { for entry in pxar::decoder::Decoder::open(archive)? {
let entry = entry?; let entry = entry?;
if verbose { if log::log_enabled!(log::Level::Debug) {
println!("{}", format_single_line_entry(&entry)); log::debug!("{}", format_single_line_entry(&entry));
} else { } else {
println!("{:?}", entry.path()); log::info!("{:?}", entry.path());
} }
} }
Ok(()) Ok(())

View File

@ -1702,11 +1702,10 @@ pub fn pxar_file_download(
channelwriter, channelwriter,
decoder, decoder,
path.clone(), path.clone(),
false,
)); ));
let zstdstream = ZstdEncoder::new(ReceiverStream::new(receiver))?; let zstdstream = ZstdEncoder::new(ReceiverStream::new(receiver))?;
Body::wrap_stream(zstdstream.map_err(move |err| { Body::wrap_stream(zstdstream.map_err(move |err| {
eprintln!("error during streaming of tar.zst '{:?}' - {}", path, err); log::error!("error during streaming of tar.zst '{:?}' - {}", path, err);
err err
})) }))
} else { } else {
@ -1714,10 +1713,9 @@ pub fn pxar_file_download(
channelwriter, channelwriter,
decoder, decoder,
path.clone(), path.clone(),
false,
)); ));
Body::wrap_stream(ReceiverStream::new(receiver).map_err(move |err| { Body::wrap_stream(ReceiverStream::new(receiver).map_err(move |err| {
eprintln!("error during streaming of zip '{:?}' - {}", path, err); log::error!("error during streaming of zip '{:?}' - {}", path, err);
err err
})) }))
} }

View File

@ -25,13 +25,13 @@ fn get_tape_handle(param: &Value) -> Result<LtoTapeHandle, Error> {
let handle = if let Some(name) = param["drive"].as_str() { let handle = if let Some(name) = param["drive"].as_str() {
let (config, _digest) = pbs_config::drive::config()?; let (config, _digest) = pbs_config::drive::config()?;
let drive: LtoTapeDrive = config.lookup("lto", name)?; let drive: LtoTapeDrive = config.lookup("lto", name)?;
eprintln!("using device {}", drive.path); log::info!("using device {}", drive.path);
open_lto_tape_drive(&drive)? open_lto_tape_drive(&drive)?
} else if let Some(device) = param["device"].as_str() { } else if let Some(device) = param["device"].as_str() {
eprintln!("using device {}", device); log::info!("using device {}", device);
LtoTapeHandle::new(open_lto_tape_device(device)?)? LtoTapeHandle::new(open_lto_tape_device(device)?)?
} else if let Some(true) = param["stdin"].as_bool() { } else if let Some(true) = param["stdin"].as_bool() {
eprintln!("using stdin"); log::info!("using stdin");
let fd = std::io::stdin().as_raw_fd(); let fd = std::io::stdin().as_raw_fd();
let file = unsafe { File::from_raw_fd(fd) }; let file = unsafe { File::from_raw_fd(fd) };
check_tape_is_lto_tape_device(&file)?; check_tape_is_lto_tape_device(&file)?;
@ -39,7 +39,7 @@ fn get_tape_handle(param: &Value) -> Result<LtoTapeHandle, Error> {
} else if let Ok(name) = std::env::var("PROXMOX_TAPE_DRIVE") { } else if let Ok(name) = std::env::var("PROXMOX_TAPE_DRIVE") {
let (config, _digest) = pbs_config::drive::config()?; let (config, _digest) = pbs_config::drive::config()?;
let drive: LtoTapeDrive = config.lookup("lto", &name)?; let drive: LtoTapeDrive = config.lookup("lto", &name)?;
eprintln!("using device {}", drive.path); log::info!("using device {}", drive.path);
open_lto_tape_drive(&drive)? open_lto_tape_drive(&drive)?
} else { } else {
let (config, _digest) = pbs_config::drive::config()?; let (config, _digest) = pbs_config::drive::config()?;
@ -55,7 +55,7 @@ fn get_tape_handle(param: &Value) -> Result<LtoTapeHandle, Error> {
if drive_names.len() == 1 { if drive_names.len() == 1 {
let name = drive_names[0]; let name = drive_names[0];
let drive: LtoTapeDrive = config.lookup("lto", name)?; let drive: LtoTapeDrive = config.lookup("lto", name)?;
eprintln!("using device {}", drive.path); log::info!("using device {}", drive.path);
open_lto_tape_drive(&drive)? open_lto_tape_drive(&drive)?
} else { } else {
bail!("no drive/device specified"); bail!("no drive/device specified");