diff --git a/env.go b/env.go index cca8ab8..82489a5 100644 --- a/env.go +++ b/env.go @@ -121,25 +121,31 @@ func extismHTTPRequest(request, body extismPointer) extismPointer func extismHTTPStatusCode() int32 // extismLogInfo logs an "info" string to the host from the previously-written UTF-8 string written to `offset`. -// Note that the memory at `offset` can be immediately freed because it is immediately logged. // //go:wasmimport extism:host/env log_info func extismLogInfo(offset extismPointer) // extismLogDebug logs a "debug" string to the host from the previously-written UTF-8 string written to `offset`. -// Note that the memory at `offset` can be immediately freed because it is immediately logged. // //go:wasmimport extism:host/env log_debug func extismLogDebug(offset extismPointer) // extismLogWarn logs a "warning" string to the host from the previously-written UTF-8 string written to `offset`. -// Note that the memory at `offset` can be immediately freed because it is immediately logged. // //go:wasmimport extism:host/env log_warn func extismLogWarn(offset extismPointer) // extismLogError logs an "error" string to the host from the previously-written UTF-8 string written to `offset`. -// Note that the memory at `offset` can be immediately freed because it is immediately logged. // //go:wasmimport extism:host/env log_error func extismLogError(offset extismPointer) + +// extismLogTrace logs an "error" string to the host from the previously-written UTF-8 string written to `offset`. +// +//go:wasmimport extism:host/env log_error +func extismLogTrace(offset extismPointer) + +// extismGetLogLevel returns the configured log level +// +//go:wasmimport extism:host/env get_log_level +func extismGetLogLevel() int32 diff --git a/extism_pdk.go b/extism_pdk.go index 1d016fb..759d3c5 100644 --- a/extism_pdk.go +++ b/extism_pdk.go @@ -15,11 +15,11 @@ type Memory struct { type LogLevel int const ( - LogInfo LogLevel = iota + LogTrace LogLevel = iota LogDebug + LogInfo LogWarn LogError - LogTrace ) func load(offset extismPointer, buf []byte) { @@ -205,6 +205,10 @@ func GetConfig(key string) (string, bool) { // LogMemory logs the `memory` block on the host using the provided log `level`. func LogMemory(level LogLevel, memory Memory) { + configuredLevel := extismGetLogLevel() + if level < LogLevel(configuredLevel) { + return + } switch level { case LogInfo: extismLogInfo(memory.offset) @@ -214,6 +218,8 @@ func LogMemory(level LogLevel, memory Memory) { extismLogWarn(memory.offset) case LogError: extismLogError(memory.offset) + case LogTrace: + extismLogTrace(memory.offset) } }