diff --git a/extism.go b/extism.go index ab1c813..1702e53 100644 --- a/extism.go +++ b/extism.go @@ -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 diff --git a/extism_test.go b/extism_test.go index d526a7f..d269f36 100644 --- a/extism_test.go +++ b/extism_test.go @@ -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)