MCPcopy Index your code
hub / github.com/bracesdev/errtrace / newExampleLogger

Function newExampleLogger

example_trace_test.go:104–117  ·  view source on GitHub ↗

newExampleLogger creates a new slog.Logger for use in examples. It omits timestamps from the output to allow for output matching, and cleans paths in trace output to make them environment-agnostic.

()

Source from the content-addressed store, hash-verified

102// It omits timestamps from the output to allow for output matching,
103// and cleans paths in trace output to make them environment-agnostic.
104func newExampleLogger() (logger *slog.Logger, printOutput func()) {
105 var buf strings.Builder
106 return slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{
107 ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
108 if len(groups) == 0 && a.Key == slog.TimeKey {
109 return slog.Attr{}
110 }
111 return a
112 },
113 })), func() {
114 fmt.Println(tracetest.MustClean(buf.String()))
115 buf.Reset()
116 }
117}

Callers 1

Example_logWithSlogFunction · 0.85

Calls 2

MustCleanFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected