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

NameTypeDescription
ctxcontext.ContextContext carrying profiling labels or an execution trace task.
categorystringLow-cardinality event category.
formatstringPrintf-style message format.
args...anyValues 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)}
Go Reference