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;
use wapc_guest::HandlerResult;
use http::{Request, Response, Handlers};
use log::{info, warn, error, trace, debug};
#[no_mangle]
pub fn wapc_init() {
http::Handlers::register_handle_request(method_logger);
logging::enable_macros();
}
fn method_logger(msg: http::Request) -> HandlerResult<http::Response> {
logging::default().write_log("", "trace", "Coercing Rust String to str");
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())
}