#wasm #wasmcloud #actor #events

wasmcloud-actor-logging

Interface to the logging contract for use by wasmCloud Actors

3 releases

0.1.2 Apr 16, 2021
0.1.1 Feb 17, 2021
0.1.0 Feb 10, 2021

#468 in WebAssembly

Download history 10/week @ 2021-02-20 22/week @ 2021-02-27 19/week @ 2021-03-06 21/week @ 2021-03-13 10/week @ 2021-03-20 9/week @ 2021-03-27 31/week @ 2021-04-03 42/week @ 2021-04-10 22/week @ 2021-04-17 6/week @ 2021-04-24 6/week @ 2021-05-01 2/week @ 2021-05-08 24/week @ 2021-05-15 5/week @ 2021-05-22 12/week @ 2021-05-29 7/week @ 2021-06-05

80 downloads per month
Used in wasmcloud-logging

Apache-2.0

11KB
142 lines

crates.io  Rust license  documentation

wasmCloud Logging Actor Interface

This crate provides an abstraction over the wasmcloud:logging contract. This allows actors to use normal log macros (like info!, warn!, error!, etc) to write logs from within the actor.

Example:

extern crate wasmcloud_actor_http_server as http;
extern crate wasmcloud_actor_logging as logging;
extern crate wasmcloud_actor_core as actor;
use wapc_guest::HandlerResult;
use http::{Request, Response, Handlers};
use log::{info, warn, error, trace, debug};

#[actor::init]
pub fn init() {
    http::Handlers::register_handle_request(method_logger);
    /// Initialize the logger to enable log macros
    logging::enable_macros();
}

/// Actor must be signed with `wasmcloud:logging` to log messages
fn method_logger(msg: http::Request) -> HandlerResult<http::Response> {
    /// Logs can be directly written via `write_log`
    logging::default().write_log("", "trace", "Coercing Rust String to str");
    
    /// After initialization, logs can be directly written from the actor using macros
    match &*msg.method {
        "GET" => info!("Received a GET request"),
        "POST" => info!("Received a POST request"),
        "PUT" => info!("Received a PUT request"),
        "DELETE" => warn!("Received a DELETE request"),
        req => error!("Received an unsupported HTTP Request: {}", req),
    };
    debug!("Finished matching HTTP method, returning OK");
    Ok(http::Response::ok())
}

Dependencies

~1–1.7MB
~39K SLoC