#capability #capability-provider #logging #wasmcloud #api-bindings

wasmcloud-interface-logging

interface for logging capability provider (wasmcloud:builtin:logging)

18 releases (10 breaking)

0.11.0 Sep 19, 2023
0.10.0 Jul 20, 2023
0.9.0 Apr 12, 2023
0.8.1 Nov 23, 2022
0.2.0 Oct 24, 2021

#1045 in WebAssembly

24 downloads per month
Used in dtbh_interface

Apache-2.0 and maybe LGPL-3.0-or-later

16KB
242 lines

crates.io  TinyGo Version

wasmCloud Builtin Logging Interface

This interface defines the wasmCloud built-in logging interface that comes with each of our supported host runtimes. Actors that use this interface must have the capability contract wasmcloud:builtin:logging in their claims list (wash claims sign --logging).

Capability Provider Implementations

There are no external implementations for this provider as they are built directly into the host runtime.

Example Usage

🦀 Rust

Logging at all available levels:

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
}

Dependencies

~13–30MB
~475K SLoC