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: display log level names #10

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions extism.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ const (
Trace
)

func (l LogLevel) String() string {
s := ""
switch l {
case Error:
s = "ERROR"
case Warn:
s = "WARN"
case Info:
s = "INFO"
case Debug:
s = "DEBUG"
case Trace:
s = "TRACE"
}
return s
}

// Plugin is used to call WASM functions
type Plugin struct {
Runtime *Runtime
Expand Down
8 changes: 8 additions & 0 deletions extism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ func TestLog_custom(t *testing.T) {

plugin.SetLogger(func(level LogLevel, message string) {
actual = append(actual, LogEntry{message: message, level: level})
switch level {
case Info:
assert.Equal(t, fmt.Sprintf("%s", level), "INFO")
case Warn:
assert.Equal(t, fmt.Sprintf("%s", level), "WARN")
case Error:
assert.Equal(t, fmt.Sprintf("%s", level), "ERROR")
}
})

plugin.SetLogLevel(Info)
Expand Down