Standard library / log/slog

slog.Bool()

Construct a keyed Bool attribute for structured logging. Expected stdout: 'key\ntrue\n'.

Formal Syntax & Structure

go syntaxgo
func Bool(key string, v bool) Attr

Parameters & Attributes

NameTypeDescription
keystringAttribute key.
vboolValues to log or convert.

Return Value

Attr

Construct a keyed Bool attribute for structured logging.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log/slog")
func main() { a := slog.Bool("key", true); fmt.Println(a.Key); fmt.Println(a.Value) }
Go Reference