Skip to content

Commit

Permalink
fix: Remove PluginConfig.LogLevel and set default log level to Off (#77)
Browse files Browse the repository at this point in the history
This fixes a bug where log level is Trace by default and removes
PluginConfig.LogLevel since we can't enforce it anymore
  • Loading branch information
mhmd-azeez authored Sep 29, 2024
1 parent 1aa7887 commit 34ceed6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 9 additions & 5 deletions extism.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type PluginConfig struct {
ModuleConfig wazero.ModuleConfig
RuntimeConfig wazero.RuntimeConfig
EnableWasi bool
LogLevel LogLevel
ObserveAdapter *observe.AdapterBase
ObserveOptions *observe.Options
}
Expand Down Expand Up @@ -147,11 +146,16 @@ func (p *Plugin) SetLogger(logger func(LogLevel, string)) {
}

func (p *Plugin) Log(level LogLevel, message string) {
if level < LogLevel(pluginLogLevel.Load()) {
return
minimumLevel := LogLevel(pluginLogLevel.Load())

// If the global log level hasn't been set, use LogLevelOff as default
if minimumLevel == logLevelUnset {
minimumLevel = LogLevelOff
}

p.log(level, message)
if level >= minimumLevel {
p.log(level, message)
}
}

func (p *Plugin) Logf(level LogLevel, format string, args ...any) {
Expand Down Expand Up @@ -351,7 +355,7 @@ var pluginLogLevel = atomic.Int32{}

// SetPluginLogLevel sets the log level for the plugin
func SetLogLevel(level LogLevel) {
pluginLogLevel.Store(int32(level.ExtismCompat()))
pluginLogLevel.Store(int32(level))
}

// NewPlugin creates a new Extism plugin with the given manifest, configuration, and host functions.
Expand Down
5 changes: 0 additions & 5 deletions extism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,6 @@ func TestLog_default(t *testing.T) {
log.SetOutput(os.Stderr)
}()

type LogEntry struct {
message string
level LogLevel
}

if plugin, ok := plugin(t, manifest); ok {
defer plugin.Close()

Expand Down
3 changes: 1 addition & 2 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ 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 Expand Up @@ -586,7 +585,7 @@ func getLogLevel(ctx context.Context, m api.Module) int32 {
// if _, ok := ctx.Value(PluginCtxKey("plugin")).(*Plugin); ok {
// panic("Invalid context, `plugin` key not found")
// }
return pluginLogLevel.Load()
return LogLevel(pluginLogLevel.Load()).ExtismCompat()
}

// EncodeI32 encodes the input as a ValueTypeI32.
Expand Down

0 comments on commit 34ceed6

Please sign in to comment.