Standard library / log/slog
slog.TextHandler.Enabled()
Test severity against the configured minimum level. Expected stdout: 'false true\n'.
Formal Syntax & Structure
go syntaxgo
func (h *TextHandler) Enabled(_ context.Context, level Level) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| _ | context.Context | Input to the operation as described above. |
| level | Level | Severity of the event or minimum level. |
Return Value
bool
Test severity against the configured minimum level.
Working Example
Example Snippetgo
package main
import ( "context" "fmt" "io" "log/slog")
func main() { h := slog.NewTextHandler(io.Discard, nil) fmt.Println(h.Enabled(context.Background(), slog.LevelDebug), h.Enabled(context.Background(), slog.LevelInfo))}