Skip to content

Commit 34ceed6

Browse files
authored
fix: Remove PluginConfig.LogLevel and set default log level to Off (#77)
This fixes a bug where log level is Trace by default and removes PluginConfig.LogLevel since we can't enforce it anymore
1 parent 1aa7887 commit 34ceed6

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

extism.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type PluginConfig struct {
5555
ModuleConfig wazero.ModuleConfig
5656
RuntimeConfig wazero.RuntimeConfig
5757
EnableWasi bool
58-
LogLevel LogLevel
5958
ObserveAdapter *observe.AdapterBase
6059
ObserveOptions *observe.Options
6160
}
@@ -147,11 +146,16 @@ func (p *Plugin) SetLogger(logger func(LogLevel, string)) {
147146
}
148147

149148
func (p *Plugin) Log(level LogLevel, message string) {
150-
if level < LogLevel(pluginLogLevel.Load()) {
151-
return
149+
minimumLevel := LogLevel(pluginLogLevel.Load())
150+
151+
// If the global log level hasn't been set, use LogLevelOff as default
152+
if minimumLevel == logLevelUnset {
153+
minimumLevel = LogLevelOff
152154
}
153155

154-
p.log(level, message)
156+
if level >= minimumLevel {
157+
p.log(level, message)
158+
}
155159
}
156160

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

352356
// SetPluginLogLevel sets the log level for the plugin
353357
func SetLogLevel(level LogLevel) {
354-
pluginLogLevel.Store(int32(level.ExtismCompat()))
358+
pluginLogLevel.Store(int32(level))
355359
}
356360

357361
// NewPlugin creates a new Extism plugin with the given manifest, configuration, and host functions.

extism_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,6 @@ func TestLog_default(t *testing.T) {
435435
log.SetOutput(os.Stderr)
436436
}()
437437

438-
type LogEntry struct {
439-
message string
440-
level LogLevel
441-
}
442-
443438
if plugin, ok := plugin(t, manifest); ok {
444439
defer plugin.Close()
445440

host.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) (
334334
logFunc("log_info", LogLevelInfo)
335335
logFunc("log_warn", LogLevelWarn)
336336
logFunc("log_error", LogLevelError)
337-
logFunc("log_trace", LogLevelTrace)
338337

339338
return builder.Instantiate(ctx)
340339
}
@@ -586,7 +585,7 @@ func getLogLevel(ctx context.Context, m api.Module) int32 {
586585
// if _, ok := ctx.Value(PluginCtxKey("plugin")).(*Plugin); ok {
587586
// panic("Invalid context, `plugin` key not found")
588587
// }
589-
return pluginLogLevel.Load()
588+
return LogLevel(pluginLogLevel.Load()).ExtismCompat()
590589
}
591590

592591
// EncodeI32 encodes the input as a ValueTypeI32.

0 commit comments

Comments
 (0)