Skip to content

Commit

Permalink
Merge pull request #4348 from cgwalters/log-tasks
Browse files Browse the repository at this point in the history
progress: Add more logging/tracing
  • Loading branch information
jmarrero authored Mar 28, 2023
2 parents d55767a + 8599347 commit 3c6ad4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rust/src/console_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use once_cell::sync::Lazy;
use std::sync::Mutex;
use std::sync::MutexGuard;

#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
enum ProgressType {
Task,
NItems(u64),
Expand Down Expand Up @@ -50,6 +50,7 @@ impl ProgressState {
fn new<M: Into<String>>(msg: M, ptype: ProgressType) -> Self {
use std::fmt::Write;
let msg = msg.into();
tracing::debug!("Creating progress {msg:?} with type {ptype:?}");
let target = ProgressDrawTarget::stdout();
let style = ProgressStyle::default_bar();
let pb = match ptype {
Expand Down Expand Up @@ -121,14 +122,21 @@ impl ProgressState {

/// For a percent or nitems progress, set the progress state.
fn update(&self, n: u64) {
assert!(!(self.ptype == ProgressType::Task));
let ptype = &self.ptype;
if ptype == &ProgressType::Task {
let message = &self.message;
panic!("expected non-task progress type; current message is {message}")
}
self.bar.set_position(n);
}

/// Clear the progress bar and print a completion message even on non-ttys.
fn end<T: AsRef<str>>(&self, suffix: Option<T>) {
let ptype = &self.ptype;
let suffix = suffix.as_ref().map(|s| s.as_ref());
tracing::debug!("Ending progress {ptype:?}; suffix={suffix:?}");
self.bar.finish_and_clear();
let suffix = suffix.as_ref().map(|s| s.as_ref()).unwrap_or("done");
let suffix = suffix.unwrap_or("done");
if self.is_hidden {
println!("{}", suffix);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/app/rpmostree-clientlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ on_transaction_progress (GDBusProxy *proxy, gchar *sender_name, gchar *signal_na
{
auto tp = static_cast<TransactionProgress *> (user_data);

g_debug ("txn progress %s", signal_name);

if (g_strcmp0 (signal_name, "SignatureProgress") == 0)
{
/* We used to print the signature here, but doing so interferes with the
Expand Down

0 comments on commit 3c6ad4c

Please sign in to comment.