From 28ed54b31d3c6da89ce34c49147ed5c8d56f0580 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 20 Sep 2024 20:18:43 +0200 Subject: [PATCH] feat: add support for `wasi:logging` Signed-off-by: Roman Volosatovs --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/sys/Cargo.toml | 2 +- src/lib.rs | 15 +++++++++++- wit/deps.lock | 10 +++++--- wit/deps/logging/logging.wit | 35 ++++++++++++++++++++++++++++ wit/deps/logging/world.wit | 5 ++++ wit/deps/passthrough/passthrough.wit | 2 ++ wit/west.wit | 2 ++ 9 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 wit/deps/logging/logging.wit create mode 100644 wit/deps/logging/world.wit diff --git a/Cargo.lock b/Cargo.lock index 046e4c1..ee6946a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2045,7 +2045,7 @@ dependencies = [ [[package]] name = "west" -version = "0.1.0" +version = "0.1.2" dependencies = [ "anyhow", "http", @@ -2068,7 +2068,7 @@ dependencies = [ [[package]] name = "west-sys" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "tracing", diff --git a/Cargo.toml b/Cargo.toml index f777179..127d7ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "west" -version = "0.1.0" +version = "0.1.2" description = "WebAssembly component test runtime" authors.workspace = true diff --git a/crates/sys/Cargo.toml b/crates/sys/Cargo.toml index a993ea9..4a3f45d 100644 --- a/crates/sys/Cargo.toml +++ b/crates/sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "west-sys" -version = "0.1.1" +version = "0.1.2" description = "WebAssembly component test runtime C bindings" authors.workspace = true diff --git a/src/lib.rs b/src/lib.rs index 6df2eee..729ef76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ use core::time::Duration; use anyhow::Context as _; -use tracing::instrument; +use tracing::{info, instrument}; use wasi_preview1_component_adapter_provider::{ WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER, }; @@ -49,6 +49,19 @@ impl WasiHttpView for Ctx { } } +impl bindings::wasi::logging::logging::Host for Ctx { + #[instrument(level = "trace", skip_all, ret(level = "trace"))] + fn log( + &mut self, + level: bindings::wasi::logging::logging::Level, + context: String, + message: String, + ) -> wasmtime::Result<()> { + info!(?level, context, message); + Ok(()) + } +} + impl bindings::wasiext::http::ext::Host for Ctx { #[instrument(level = "trace", skip_all, ret(level = "trace"))] fn new_response_outparam( diff --git a/wit/deps.lock b/wit/deps.lock index e861d62..ae35b36 100644 --- a/wit/deps.lock +++ b/wit/deps.lock @@ -22,11 +22,15 @@ sha512 = "124cbe0e0c97856d3bdb504ea569c212652fe534abd151d29b7957d3ce59435690ecf8 sha256 = "2a74bd811adc46b5a0f19827ddbde89870e52b17615f4d0873f06fd977250caf" sha512 = "94624f00c66e66203592cee820f80b1ba91ecdb71f682c154f25eaf71f8d8954197dcb64503bc21e72ed5e812af7eae876df47b7eb727b02db3a74a7ce0aefca" +[logging] +sha256 = "9676b482485bb0fd2751a390374c1108865a096b7037f4b5dbe524f066bfb06e" +sha512 = "30a621a6d48a0175e8047c062e618523a85f69c45a7c31918da2b888f7527fce1aca67fa132552222725d0f6cdcaed95be7f16c28488d9468c0fad00cb7450b9" + [passthrough] url = "https://github.com/wasiext/passthrough/archive/main.tar.gz" -sha256 = "2b1d396cb65661c8e72a227b595615bfff852e5e1d11a4c757e2edfd88f2d69e" -sha512 = "24548865215c168b13dc51c92b7a96b34d1d37ac9915f639db1e4e7fd0d4a8feff745d038d526974e28a8a8fe34c45f4a5b19282b522bde09d2d67bf653addfc" -deps = ["cli", "clocks", "filesystem", "http", "httpext", "io", "random", "sockets"] +sha256 = "e0e68af9daec38b16b3c7697e94e806837640c8f8eb165cc309257a17e78a393" +sha512 = "da9a4566a004ab549bc02b96a57591ff2dde19c6561a5079f492e585cd60b0263d01276d26605c953dce93723bf58ee3b02c3d3a1911ba457b625cec39938716" +deps = ["cli", "clocks", "filesystem", "http", "httpext", "io", "logging", "random", "sockets"] [random] sha256 = "9e2d5056186f81b2e7f96bc97d2babd0341840f6abb4f170449b70992f1b598f" diff --git a/wit/deps/logging/logging.wit b/wit/deps/logging/logging.wit new file mode 100644 index 0000000..8c0bdf8 --- /dev/null +++ b/wit/deps/logging/logging.wit @@ -0,0 +1,35 @@ +/// WASI Logging is a logging API intended to let users emit log messages with +/// simple priority levels and context values. +interface logging { + /// A log level, describing a kind of message. + enum level { + /// Describes messages about the values of variables and the flow of + /// control within a program. + trace, + + /// Describes messages likely to be of interest to someone debugging a + /// program. + debug, + + /// Describes messages likely to be of interest to someone monitoring a + /// program. + info, + + /// Describes messages indicating hazardous situations. + warn, + + /// Describes messages indicating serious errors. + error, + + /// Describes messages indicating fatal errors. + critical, + } + + /// Emit a log message. + /// + /// A log message has a `level` describing what kind of message is being + /// sent, a context, which is an uninterpreted string meant to help + /// consumers group similar messages, and a string containing the message + /// text. + log: func(level: level, context: string, message: string); +} diff --git a/wit/deps/logging/world.wit b/wit/deps/logging/world.wit new file mode 100644 index 0000000..ede6286 --- /dev/null +++ b/wit/deps/logging/world.wit @@ -0,0 +1,5 @@ +package wasi:logging; + +world imports { + import logging; +} diff --git a/wit/deps/passthrough/passthrough.wit b/wit/deps/passthrough/passthrough.wit index 76a4faf..de4dbe2 100644 --- a/wit/deps/passthrough/passthrough.wit +++ b/wit/deps/passthrough/passthrough.wit @@ -19,6 +19,7 @@ world passthrough { export wasi:io/error@0.2.1; export wasi:io/poll@0.2.1; export wasi:io/streams@0.2.1; + export wasi:logging/logging; export wasi:random/insecure-seed@0.2.1; export wasi:random/insecure@0.2.1; export wasi:random/random@0.2.1; @@ -47,6 +48,7 @@ world passthrough { import wasi:io/error@0.2.1; import wasi:io/poll@0.2.1; import wasi:io/streams@0.2.1; + import wasi:logging/logging; import wasi:random/insecure-seed@0.2.1; import wasi:random/insecure@0.2.1; import wasi:random/random@0.2.1; diff --git a/wit/west.wit b/wit/west.wit index d0cd0f0..b0ad18e 100644 --- a/wit/west.wit +++ b/wit/west.wit @@ -2,4 +2,6 @@ package west:west@0.1.0; world imports { include wasiext:http/imports@0.1.0; + + import wasi:logging/logging; }