Skip to content

Commit

Permalink
feat: display log level names (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice authored Aug 7, 2023
1 parent 1d45fb5 commit 2e50fda
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit 2e50fda

Please sign in to comment.