Standard library / log/slog
slog.Duration()
Construct a keyed Duration attribute for structured logging. Expected stdout: 'key\n2s\n'.
Formal Syntax & Structure
go syntaxgo
func Duration(key string, v time.Duration) AttrParameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | string | Attribute key. |
| v | time.Duration | Values to log or convert. |
Return Value
Attr
Construct a keyed Duration attribute for structured logging.
Working Example
Example Snippetgo
package main
import ( "fmt" "log/slog" "time")
func main() { a := slog.Duration("key", 2*time.Second); fmt.Println(a.Key); fmt.Println(a.Value) }