From f2135f4bcb223850f7895692a24b904e4933ec14 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Mon, 2 Oct 2023 16:27:59 +0800 Subject: [PATCH] Converting more log statements to structured logging --- lib/wasix/src/state/env.rs | 50 ++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/wasix/src/state/env.rs b/lib/wasix/src/state/env.rs index 1b6d3eed282..fc168ad538f 100644 --- a/lib/wasix/src/state/env.rs +++ b/lib/wasix/src/state/env.rs @@ -493,7 +493,11 @@ impl WasiEnv { let instance = match Instance::new(&mut store, &module, &import_object) { Ok(a) => a, Err(err) => { - tracing::error!("wasi[{}]::wasm instantiate error ({})", pid, err); + tracing::error!( + %pid, + error = &err as &dyn std::error::Error, + "Instantiation failed", + ); func_env .data(&store) .blocking_cleanup(Some(Errno::Noexec.into())); @@ -508,7 +512,11 @@ impl WasiEnv { if let Err(err) = func_env.initialize_with_memory(&mut store, instance.clone(), imported_memory, true) { - tracing::error!("wasi[{}]::wasi initialize error ({})", pid, err); + tracing::error!( + %pid, + error = &err as &dyn std::error::Error, + "Initialization failed", + ); func_env .data(&store) .blocking_cleanup(Some(Errno::Noexec.into())); @@ -579,7 +587,7 @@ impl WasiEnv { let exit_code = env.thread.set_or_get_exit_code_for_signal(sig); return Err(WasiError::Exit(exit_code)); } else { - trace!("wasi[{}]::signal-ignored: {:?}", env.pid(), sig); + tracing::trace!(pid=%env.pid(), ?sig, "Signal ignored"); } } return Ok(Ok(true)); @@ -660,25 +668,25 @@ impl WasiEnv { for signal in signals { tracing::trace!( - "wasi[{}]::processing-signal: {:?}", - ctx.data().pid(), - signal + pid=%ctx.data().pid(), + ?signal + "Processing signal", ); if let Err(err) = handler.call(ctx, signal as i32) { match err.downcast::() { Ok(wasi_err) => { - warn!( - "wasi[{}]::signal handler wasi error - {}", - ctx.data().pid(), - wasi_err + tracing::warn!( + pid=%ctx.data().pid(), + wasi_err=&wasi_err as &dyn std::error::Error, + "signal handler wasi error", ); return Err(wasi_err); } Err(runtime_err) => { - warn!( - "wasi[{}]::signal handler runtime error - {}", - ctx.data().pid(), - runtime_err + tracing::warn!( + pid=%ctx.data().pid(), + runtime_err=&runtime_err as &dyn std::error::Error, + "signal handler runtime error", ); return Err(WasiError::Exit(Errno::Intr.into())); } @@ -696,13 +704,19 @@ impl WasiEnv { // Check for forced exit if let Some(forced_exit) = self.thread.try_join() { return Some(forced_exit.unwrap_or_else(|err| { - tracing::debug!("exit runtime error - {}", err); + tracing::debug!( + error = &*err as &dyn std::error::Error, + "exit runtime error", + ); Errno::Child.into() })); } if let Some(forced_exit) = self.process.try_join() { return Some(forced_exit.unwrap_or_else(|err| { - tracing::debug!("exit runtime error - {}", err); + tracing::debug!( + error = &*err as &dyn std::error::Error, + "exit runtime error", + ); Errno::Child.into() })); } @@ -875,7 +889,7 @@ impl WasiEnv { // We first need to copy any files in the package over to the // main file system if let Err(e) = InlineWaker::block_on(root_fs.merge(&pkg.webc_fs)) { - warn!( + tracing::warn!( error = &e as &dyn std::error::Error, "Unable to merge the package's filesystem into the main one", ); @@ -1029,7 +1043,7 @@ impl WasiEnv { // If this is the main thread then also close all the files if self.thread.is_main() { - trace!("wasi[{}]:: cleaning up open file handles", self.pid()); + tracing::trace!(pid=%self.pid(), "cleaning up open file handles"); // Now send a signal that the thread is terminated self.process.signal_process(Signal::Sigquit);