Skip to content

Commit 43606a7

Browse files
committed
utils: Add a log_debug() helper
ref #793 And add a log at trace level unconditionally. Signed-off-by: Colin Walters <[email protected]>
1 parent ecabb89 commit 43606a7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/src/blockdev.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub(crate) fn list_dev(dev: &Utf8Path) -> Result<Device> {
9898
let mut devs: DevicesOutput = Command::new("lsblk")
9999
.args(["-J", "-b", "-O"])
100100
.arg(dev)
101+
.log_debug()
101102
.run_and_parse_json()?;
102103
for dev in devs.blockdevices.iter_mut() {
103104
dev.backfill_missing()?;

utils/src/command.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use anyhow::{Context, Result};
77

88
/// Helpers intended for [`std::process::Command`].
99
pub trait CommandRunExt {
10+
fn log_debug(&mut self) -> &mut Self;
1011
fn run(&mut self) -> Result<()>;
1112
/// Execute the child process, parsing its stdout as JSON.
1213
fn run_and_parse_json<T: serde::de::DeserializeOwned>(&mut self) -> Result<T>;
@@ -68,9 +69,17 @@ impl CommandRunExt for Command {
6869
fn run(&mut self) -> Result<()> {
6970
let stderr = tempfile::tempfile()?;
7071
self.stderr(stderr.try_clone()?);
72+
tracing::trace!("exec: {self:?}");
7173
self.status()?.check_status(stderr)
7274
}
7375

76+
/// Output a debug-level log message with this command.
77+
fn log_debug(&mut self) -> &mut Self {
78+
tracing::debug!("exec: {self:?}");
79+
self
80+
}
81+
82+
/// Synchronously execute the child, and parse its stdout as JSON.
7483
fn run_and_parse_json<T: serde::de::DeserializeOwned>(&mut self) -> Result<T> {
7584
let mut stdout = tempfile::tempfile()?;
7685
self.stdout(stdout.try_clone()?);

0 commit comments

Comments
 (0)