Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support trace log level #73

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions extism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,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 @@ -463,7 +463,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 @@ -474,6 +474,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 @@ -485,7 +487,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 an 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointing to this: extism/go-pdk@7cb3d48

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.
Loading