Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for wasi:logging #29

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "west"
version = "0.1.0"
version = "0.1.2"
description = "WebAssembly component test runtime"

authors.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions wit/deps.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 35 additions & 0 deletions wit/deps/logging/logging.wit
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions wit/deps/logging/world.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package wasi:logging;

world imports {
import logging;
}
2 changes: 2 additions & 0 deletions wit/deps/passthrough/passthrough.wit
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ world passthrough {
export wasi:io/[email protected];
export wasi:io/[email protected];
export wasi:io/[email protected];
export wasi:logging/logging;
export wasi:random/[email protected];
export wasi:random/[email protected];
export wasi:random/[email protected];
Expand Down Expand Up @@ -47,6 +48,7 @@ world passthrough {
import wasi:io/[email protected];
import wasi:io/[email protected];
import wasi:io/[email protected];
import wasi:logging/logging;
import wasi:random/[email protected];
import wasi:random/[email protected];
import wasi:random/[email protected];
Expand Down
2 changes: 2 additions & 0 deletions wit/west.wit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package west:[email protected];

world imports {
include wasiext:http/imports@0.1.0;

import wasi:logging/logging;
}
Loading