Standard library / runtime/trace
trace.Logf()
Record a formatted trace event. Keep categories bounded and avoid secrets in messages. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Logf(ctx context.Context, category, format string, args ...any)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Context carrying profiling labels or an execution trace task. |
| category | string | Low-cardinality event category. |
| format | string | Printf-style message format. |
| args | ...any | Values substituted into the format string. |
Working Example
Example Snippetgo
package main
import ( "bytes" "context" "fmt" "runtime/trace")
func main() { var b bytes.Buffer if err := trace.Start(&b); err != nil { panic(err) } trace.Logf(context.Background(), "phase", "items=%d", 3) trace.Stop() fmt.Println(b.Len() > 0)}