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: ```rust extern crate wasmcloudactorhttpserver as http; extern crate wasmcloudactorlogging as logging; use wapcguest::HandlerResult; use http::{Request, Response, Handlers}; use log::{info, warn, error, trace, debug};
pub fn wapcinit() { http::Handlers::registerhandlerequest(methodlogger); /// Initialize the logger to enable log macros logging::enable_macros(); }
/// Actor must be signed with wasmcloud:logging
to log messages
fn methodlogger(msg: http::Request) -> HandlerResulthttp::Response {
/// Logs can be directly written via write_log
logging::default().writelog("", "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())
} ```