Skip to content

Commit

Permalink
fix: add trace level logging (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko authored Oct 14, 2024
1 parent a82df46 commit c3d9ce3
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use extism_pdk::*;

#[plugin_fn]
pub fn http_get(Json(req): Json<HttpRequest>) -> FnResult<Memory> {
trace!("HTTP Request: {:?}", req);
info!("Request to: {}", req.url);
let res = http::request::<()>(&req, None)?;
Ok(res.into_memory())
Expand Down
1 change: 1 addition & 0 deletions src/extism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
pub fn log_debug(offs: u64);
pub fn log_warn(offs: u64);
pub fn log_error(offs: u64);
pub fn log_trace(offs: u64);
}

/// Loads a byte array from Extism's memory. Only use this if you
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum LogLevel {
Debug,
Warn,
Error,
Trace,
}

/// Re-export of `serde_json`
Expand Down
7 changes: 7 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ macro_rules! error {
}
}

#[macro_export]
macro_rules! trace {
($($arg:tt)+) => {
$crate::log!($crate::LogLevel::Trace, $($arg)+)
}
}

#[macro_export]
macro_rules! unwrap {
($x:expr) => {
Expand Down
1 change: 1 addition & 0 deletions src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl Memory {
LogLevel::Debug => extism::log_debug(self.0.offset),
LogLevel::Warn => extism::log_warn(self.0.offset),
LogLevel::Error => extism::log_error(self.0.offset),
LogLevel::Trace => extism::log_trace(self.0.offset),
}
}
}
Expand Down
Binary file modified test/code.wasm
Binary file not shown.
Binary file modified test/host_function.wasm
Binary file not shown.
Binary file modified test/http.wasm
Binary file not shown.

0 comments on commit c3d9ce3

Please sign in to comment.