Skip to content

Commit

Permalink
Converting more log statements to structured logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Oct 2, 2023
1 parent a4c286e commit f2135f4
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions lib/wasix/src/state/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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::<WasiError>() {
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()));
}
Expand All @@ -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()
}));
}
Expand Down Expand Up @@ -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",
);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f2135f4

Please sign in to comment.