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) bool

Parameters & Attributes

NameTypeDescription
_context.ContextInput to the operation as described above.
levelLevelSeverity 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))}
Go Reference