Skip to content

Commit 55cb612

Browse files
authored
chore: add trace logging (#48)
1 parent cf652fc commit 55cb612

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

env.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,31 @@ func extismHTTPStatusCode() int32
126126
func extismHTTPHeaders() extismPointer
127127

128128
// extismLogInfo logs an "info" string to the host from the previously-written UTF-8 string written to `offset`.
129-
// Note that the memory at `offset` can be immediately freed because it is immediately logged.
130129
//
131130
//go:wasmimport extism:host/env log_info
132131
func extismLogInfo(offset extismPointer)
133132

134133
// extismLogDebug logs a "debug" string to the host from the previously-written UTF-8 string written to `offset`.
135-
// Note that the memory at `offset` can be immediately freed because it is immediately logged.
136134
//
137135
//go:wasmimport extism:host/env log_debug
138136
func extismLogDebug(offset extismPointer)
139137

140138
// extismLogWarn logs a "warning" string to the host from the previously-written UTF-8 string written to `offset`.
141-
// Note that the memory at `offset` can be immediately freed because it is immediately logged.
142139
//
143140
//go:wasmimport extism:host/env log_warn
144141
func extismLogWarn(offset extismPointer)
145142

146143
// extismLogError logs an "error" string to the host from the previously-written UTF-8 string written to `offset`.
147-
// Note that the memory at `offset` can be immediately freed because it is immediately logged.
148144
//
149145
//go:wasmimport extism:host/env log_error
150146
func extismLogError(offset extismPointer)
147+
148+
// extismLogTrace logs an "error" string to the host from the previously-written UTF-8 string written to `offset`.
149+
//
150+
//go:wasmimport extism:host/env log_error
151+
func extismLogTrace(offset extismPointer)
152+
153+
// extismGetLogLevel returns the configured log level
154+
//
155+
//go:wasmimport extism:host/env get_log_level
156+
func extismGetLogLevel() int32

extism_pdk.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ type Memory struct {
1515
type LogLevel int
1616

1717
const (
18-
LogInfo LogLevel = iota
18+
LogTrace LogLevel = iota
1919
LogDebug
20+
LogInfo
2021
LogWarn
2122
LogError
22-
LogTrace
2323
)
2424

2525
func load(offset extismPointer, buf []byte) {
@@ -205,6 +205,10 @@ func GetConfig(key string) (string, bool) {
205205

206206
// LogMemory logs the `memory` block on the host using the provided log `level`.
207207
func LogMemory(level LogLevel, memory Memory) {
208+
configuredLevel := extismGetLogLevel()
209+
if level < LogLevel(configuredLevel) {
210+
return
211+
}
208212
switch level {
209213
case LogInfo:
210214
extismLogInfo(memory.offset)
@@ -214,6 +218,8 @@ func LogMemory(level LogLevel, memory Memory) {
214218
extismLogWarn(memory.offset)
215219
case LogError:
216220
extismLogError(memory.offset)
221+
case LogTrace:
222+
extismLogTrace(memory.offset)
217223
}
218224
}
219225

0 commit comments

Comments
 (0)