Standard library / log/slog

slog.String()

Construct a keyed String attribute for structured logging. Expected stdout: 'key\ngo\n'.

Formal Syntax & Structure

go syntaxgo
func String(key, value string) Attr

Parameters & Attributes

NameTypeDescription
keystringAttribute key.
valuestringInput to the operation as described above.

Return Value

Attr

Construct a keyed String attribute for structured logging.

Working Example

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