From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v3 08/10] replace print with log macro
Date: Wed, 15 Jun 2022 08:19:55 +0000 [thread overview]
Message-ID: <20220615081957.33511-10-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220615081957.33511-1-h.laimer@proxmox.com>
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
examples/upload-speed.rs | 2 +-
.../src/proxmox_restore_daemon/api.rs | 1 -
pxar-bin/Cargo.toml | 1 +
pxar-bin/src/main.rs | 49 +++++--------------
src/api2/admin/datastore.rs | 6 +--
src/bin/sg-tape-cmd.rs | 10 ++--
6 files changed, 20 insertions(+), 49 deletions(-)
diff --git a/examples/upload-speed.rs b/examples/upload-speed.rs
index 3579db96..f9fc52a8 100644
--- a/examples/upload-speed.rs
+++ b/examples/upload-speed.rs
@@ -29,7 +29,7 @@ async fn upload_speed() -> Result<f64, Error> {
.await?;
println!("start upload speed test");
- let res = client.upload_speedtest(true).await?;
+ let res = client.upload_speedtest().await?;
Ok(res)
}
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
index aeb5a71d..676deb59 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
@@ -336,7 +336,6 @@ fn extract(
entries_max: ENCODER_MAX_ENTRIES,
device_set: None,
patterns,
- verbose: false,
skip_lost_and_found: false,
};
diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml
index a5ecb039..960b0539 100644
--- a/pxar-bin/Cargo.toml
+++ b/pxar-bin/Cargo.toml
@@ -12,6 +12,7 @@ path = "src/main.rs"
anyhow = "1.0"
futures = "0.3"
nix = "0.24"
+log = "0.4"
serde_json = "1.0"
tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] }
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index e3eba213..3714eb03 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -23,7 +23,6 @@ fn extract_archive_from_reader<R: std::io::Read>(
reader: &mut R,
target: &str,
feature_flags: Flags,
- verbose: bool,
options: PxarExtractOptions,
) -> Result<(), Error> {
pbs_client::pxar::extract_archive(
@@ -31,9 +30,7 @@ fn extract_archive_from_reader<R: std::io::Read>(
Path::new(target),
feature_flags,
|path| {
- if verbose {
- println!("{:?}", path);
- }
+ log::debug!("{:?}", path);
},
options,
)
@@ -58,11 +55,6 @@ fn extract_archive_from_reader<R: std::io::Read>(
description: "Target directory",
optional: true,
},
- verbose: {
- description: "Verbose output.",
- optional: true,
- default: false,
- },
"no-xattrs": {
description: "Ignore extended file attributes.",
optional: true,
@@ -116,7 +108,6 @@ fn extract_archive(
archive: String,
pattern: Option<Vec<String>>,
target: Option<String>,
- verbose: bool,
no_xattrs: bool,
no_fcaps: bool,
no_acls: bool,
@@ -179,7 +170,7 @@ fn extract_archive(
// otherwise we want to log them but not act on them
Some(Box::new(move |err| {
was_ok.store(false, Ordering::Release);
- eprintln!("error: {}", err);
+ log::error!("error: {}", err);
Ok(())
})
as Box<dyn FnMut(Error) -> Result<(), Error> + Send>)
@@ -195,14 +186,12 @@ fn extract_archive(
if archive == "-" {
let stdin = std::io::stdin();
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 {
- if verbose {
- println!("PXAR extract: {}", archive);
- }
+ log::debug!("PXAR extract: {}", archive);
let file = std::fs::File::open(archive)?;
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) {
@@ -221,11 +210,6 @@ fn extract_archive(
source: {
description: "Source directory.",
},
- verbose: {
- description: "Verbose output.",
- optional: true,
- default: false,
- },
"no-xattrs": {
description: "Ignore extended file attributes.",
optional: true,
@@ -285,7 +269,6 @@ fn extract_archive(
async fn create_archive(
archive: String,
source: String,
- verbose: bool,
no_xattrs: bool,
no_fcaps: bool,
no_acls: bool,
@@ -318,7 +301,6 @@ async fn create_archive(
entries_max: entries_max as usize,
device_set,
patterns,
- verbose,
skip_lost_and_found: false,
};
@@ -363,9 +345,7 @@ async fn create_archive(
writer,
feature_flags,
move |path| {
- if verbose {
- println!("{:?}", path);
- }
+ log::debug!("{:?}", path);
Ok(())
},
None,
@@ -404,9 +384,7 @@ async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Re
select! {
res = session.fuse() => res?,
_ = interrupt.recv().fuse() => {
- if verbose {
- eprintln!("interrupted");
- }
+ log::debug!("interrupted");
}
}
@@ -419,23 +397,18 @@ async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Re
archive: {
description: "Archive name.",
},
- verbose: {
- description: "Verbose output.",
- optional: true,
- default: false,
- },
},
},
)]
/// 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)? {
let entry = entry?;
- if verbose {
- println!("{}", format_single_line_entry(&entry));
+ if log::log_enabled!(log::Level::Debug) {
+ log::debug!("{}", format_single_line_entry(&entry));
} else {
- println!("{:?}", entry.path());
+ log::info!("{:?}", entry.path());
}
}
Ok(())
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index ad2744b7..5448fa10 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -1702,11 +1702,10 @@ pub fn pxar_file_download(
channelwriter,
decoder,
path.clone(),
- false,
));
let zstdstream = ZstdEncoder::new(ReceiverStream::new(receiver))?;
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
}))
} else {
@@ -1714,10 +1713,9 @@ pub fn pxar_file_download(
channelwriter,
decoder,
path.clone(),
- false,
));
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
}))
}
diff --git a/src/bin/sg-tape-cmd.rs b/src/bin/sg-tape-cmd.rs
index 402fe9cb..c4567896 100644
--- a/src/bin/sg-tape-cmd.rs
+++ b/src/bin/sg-tape-cmd.rs
@@ -25,13 +25,13 @@ fn get_tape_handle(param: &Value) -> Result<LtoTapeHandle, Error> {
let handle = if let Some(name) = param["drive"].as_str() {
let (config, _digest) = pbs_config::drive::config()?;
let drive: LtoTapeDrive = config.lookup("lto", name)?;
- eprintln!("using device {}", drive.path);
+ log::info!("using device {}", drive.path);
open_lto_tape_drive(&drive)?
} 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)?)?
} 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 file = unsafe { File::from_raw_fd(fd) };
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") {
let (config, _digest) = pbs_config::drive::config()?;
let drive: LtoTapeDrive = config.lookup("lto", &name)?;
- eprintln!("using device {}", drive.path);
+ log::info!("using device {}", drive.path);
open_lto_tape_drive(&drive)?
} else {
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 {
let name = drive_names[0];
let drive: LtoTapeDrive = config.lookup("lto", name)?;
- eprintln!("using device {}", drive.path);
+ log::info!("using device {}", drive.path);
open_lto_tape_drive(&drive)?
} else {
bail!("no drive/device specified");
--
2.30.2
next prev parent reply other threads:[~2022-06-15 8:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-15 8:19 [pbs-devel] [PATCH-SERIES proxmox-backup/proxmox v3 00/10] replace print by log macro in libraries Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox v3 1/1] router: add init_cli_logger helper function Hannes Laimer
2022-06-21 8:40 ` [pbs-devel] applied: " Wolfgang Bumiller
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 01/10] bins: init cli logger Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 02/10] pbs-client: replace print with log macro Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 03/10] pbs-datastore: " Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 04/10] pbs-fuse+pbs-tape: " Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 05/10] proxmox-backup-client: " Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 06/10] proxmox-file-restore: " Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 07/10] proxmox-rest-server: " Hannes Laimer
2022-06-15 8:19 ` Hannes Laimer [this message]
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 09/10] docs: add note for setting verbosity level Hannes Laimer
2022-06-15 8:19 ` [pbs-devel] [PATCH proxmox-backup v3 10/10] fixed_index: remove unused 'print_info' function Hannes Laimer
2022-06-21 8:46 ` [pbs-devel] applied-series: [PATCH-SERIES proxmox-backup/proxmox v3 00/10] replace print by log macro in libraries Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220615081957.33511-10-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.