18 个版本 (10 个重大更新)
0.11.0 | 2023年9月19日 |
---|---|
0.10.0 | 2023年7月20日 |
0.9.0 | 2023年4月12日 |
0.8.1 | 2022年11月23日 |
0.2.0 | 2021年10月24日 |
781 在 WebAssembly 中
每月139 次下载
在 dtbh_interface 中使用
16KB
242 行
WasmCloud内置日志接口
此接口定义了wasmCloud内置日志接口,该接口包含在每个支持的主机运行时中。使用此接口的演员必须在他们的声明列表中具有能力合约 wasmcloud:builtin:logging
(wash claims sign --logging
)。
能力提供程序实现
此提供程序没有外部实现,因为它们是直接构建在主机运行时中的。
示例使用
🦀 Rust
所有可用的日志级别
use wasmbus_rpc::actor::prelude::RpcResult;
use wasmcloud_interface_logging::{debug, error, info, warn};
// Note: The function you're logging in _must_ be async. This is due to the
// way our logging macros work and is a known limitation of actor logging
async fn log_to_all() -> RpcResult<()> {
debug!("Watch out for moths");
info!("This is an info level log!");
warn!("Some viewers may find the following log disturbing");
error!("I can't let you do that, Dave");
Ok(())
}
🐭 Golang
import (
"github.com/wasmcloud/actor-tinygo"
httpserver "github.com/wasmcloud/interfaces/httpserver/tinygo"
logging "github.com/wasmcloud/interfaces/logging/tinygo"
)
type Actor struct {
logger *logging.LoggingSender
}
func main() {
me := Actor{
logger: logging.NewProviderLogging(),
}
// The calls to WriteLog require an actor.Context that is
// accessed from any invocation
actor.RegisterHandlers(httpserver.HttpServerHandler(&me))
}
func (e *Actor) HandleRequest(ctx *actor.Context, req httpserver.HttpRequest) (*httpserver.HttpResponse, error) {
_ = e.logger.WriteLog(ctx, logging.LogEntry{Level: "debug", Text: "This is a debug log"})
_ = e.logger.WriteLog(ctx, logging.LogEntry{Level: "info", Text: "This is an info log"})
_ = e.logger.WriteLog(ctx, logging.LogEntry{Level: "warn", Text: "This is a warn log"})
_ = e.logger.WriteLog(ctx, logging.LogEntry{Level: "error", Text: "This is an error log"})
return nil, nil
}
依赖项
~12–30MB
~485K SLoC