Standard library / log/slog
slog.Logger.Enabled()
Ask the handler whether an event at the given level is enabled. Expected stdout: 'false true\n'.
Formal Syntax & Structure
go syntaxgo
func (l *Logger) Enabled(ctx context.Context, level Level) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Context passed to the handler. |
| level | Level | Severity of the event or minimum level. |
Return Value
bool
Ask the handler whether an event at the given level is enabled.
Working Example
Example Snippetgo
package main
import ( "context" "fmt" "io" "log/slog")
func main() { l := slog.New(slog.NewTextHandler(io.Discard, nil)) fmt.Println(l.Enabled(context.Background(), slog.LevelDebug), l.Enabled(context.Background(), slog.LevelInfo))}