use pdk::logger;
// [...]
let value = "there!";
logger::debug!("Hello there!");
logger::info!("Hello {}", value);
logger::warn!("Hello {value}");
logger::error!("Hello {}", "there!"); into_headers_state().await
Configuring Policy Logging
Flex Gateway Policy Development Kit (PDK) provides a logging mechanism that generates a log message enriched with the API instance ID, policy ID, and request ID.
Insert custom logs with the following macros by using the pdk::logger;
package:
-
logger::debug!
-
logger::info!
-
logger::warn!
-
logger::error!
The macros behave the same as the Rust std::format! macro. The first parameter must be a format string literal. Use {}
in the literal to pass parameters, for example:
All examples appear in the Flex Gateway logs in the following format:
[flex-gateway-envoy][<log-level>] wasm log <policy-name>.<api-instance-name> main: [policy: <policy-name>][api: <api-instance-name>][req: <request-id> ] Hello there!
For more information about viewing Flex Gateway logs, see Monitoring Flex Gateway.