A small Go debug-print helper that writes values as indented JSON with a timestamp and caller reference.
Use go get to download the dependency.
go get github.com/sfate/amapretty@latestThen, import it in your Go files:
import "github.com/sfate/amapretty"Use Print and Printf to write to stdout:
amapretty.Print("string value")
amapretty.Print([]struct { Name string }{ { Name: "One" }, { Name: "Chosen" } })
amapretty.Printf("user_id=%d", 123)Use Fprint and Fprintf when you want to choose the destination writer:
var buf bytes.Buffer
_, err := amapretty.Fprint(&buf, "string value")
_, err = amapretty.Fprintf(&buf, "user_id=%d", 123)Output contains the fixed amapretty prefix, an RFC3339 timestamp, the caller
file and line, and an indented JSON array of the provided values:
[amapretty] 2023-02-24T05:02:03Z main.go:101 -- [
"string value"
]
Caller paths inside the current working directory are printed relative to that directory. Paths outside it remain absolute.
ANSI colors are emitted only when the destination writer is a terminal. Set
NO_COLOR to disable colors.
If a value cannot be encoded as JSON, amapretty prints a JSON object containing the marshal error and a Go-syntax fallback representation of the arguments.