Skip to content

Commit

Permalink
feat: support trace log level (#73)
Browse files Browse the repository at this point in the history
## Description of the change
Add support for logtrace Go SDK

## Issue Reference
#72 that is a logical step after
[this](extism/go-pdk#37)

## Checklist
- [] Documentation added/updated

---------

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
hilaryRope and [email protected] authored Aug 28, 2024
1 parent ebab3e7 commit 39b5924
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
9 changes: 6 additions & 3 deletions extism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func TestLog_default(t *testing.T) {
logs := buf.String()

assert.Contains(t, logs, "this is a warning log")
assert.Contains(t, logs, "this is an erorr log")
assert.Contains(t, logs, "this is an error log")
}
}
}
Expand All @@ -465,7 +465,7 @@ func TestLog_custom(t *testing.T) {
if plugin, ok := plugin(t, manifest); ok {
defer plugin.Close()

actual := []LogEntry{}
var actual []LogEntry

plugin.SetLogger(func(level LogLevel, message string) {
actual = append(actual, LogEntry{message: message, level: level})
Expand All @@ -476,6 +476,8 @@ func TestLog_custom(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%s", level), "WARN")
case LogLevelError:
assert.Equal(t, fmt.Sprintf("%s", level), "ERROR")
case LogLevelTrace:
assert.Equal(t, fmt.Sprintf("%s", level), "TRACE")
}
})

Expand All @@ -487,7 +489,8 @@ func TestLog_custom(t *testing.T) {
expected := []LogEntry{
{message: "this is an info log", level: LogLevelInfo},
{message: "this is a warning log", level: LogLevelWarn},
{message: "this is an erorr log", level: LogLevelError}}
{message: "this is an error log", level: LogLevelError},
{message: "this is a trace log", level: LogLevelTrace}}

assert.Equal(t, expected, actual)
}
Expand Down
3 changes: 2 additions & 1 deletion host.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) (
if plugin, ok := ctx.Value("plugin").(*Plugin); ok {
message, err := plugin.currentPlugin().ReadString(offset)
if err != nil {
panic(fmt.Errorf("Failed to read log message from memory: %v", err))
panic(fmt.Errorf("failed to read log message from memory: %v", err))
}

plugin.Log(level, message)
Expand All @@ -325,6 +325,7 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) (
logFunc("log_info", LogLevelInfo)
logFunc("log_warn", LogLevelWarn)
logFunc("log_error", LogLevelError)
logFunc("log_trace", LogLevelTrace)

return builder.Instantiate(ctx)
}
Expand Down
5 changes: 1 addition & 4 deletions plugins/log/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/extism/extism-sdk-plugins-log

go 1.20

require (
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
)
require github.com/extism/go-pdk v1.0.7-0.20240804170849-7cb3d48ce7cc
8 changes: 2 additions & 6 deletions plugins/log/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64 h1:IfR1k741q+yQLvv5sLShCkvt3FgKU4wQVJfp7hhb/iY=
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64/go.mod h1:1wdiAoG8306g4WK+6laBrS+75089/0V4XRVTllt8b5U=
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 h1:uSo+K1JhsMlamDmaxyAGj0dGExZHLsL+Edyug0dC+uk=
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
github.com/extism/go-pdk v1.0.7-0.20240804170849-7cb3d48ce7cc h1:Uuqj6uSzCbQ0BVATaEupDztLPSLSaUjcHpVQGyWA5cg=
github.com/extism/go-pdk v1.0.7-0.20240804170849-7cb3d48ce7cc/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
1 change: 1 addition & 0 deletions plugins/log/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func run_test() int32 {
pdk.Log(pdk.LogInfo, "this is an info log")
pdk.Log(pdk.LogWarn, "this is a warning log")
pdk.Log(pdk.LogError, "this is an error log")
pdk.Log(pdk.LogTrace, "this is a trace log")

return 0
}
Expand Down
Binary file modified wasm/log.wasm
Binary file not shown.

0 comments on commit 39b5924

Please sign in to comment.