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.
()
| 102 | // It omits timestamps from the output to allow for output matching, |
| 103 | // and cleans paths in trace output to make them environment-agnostic. |
| 104 | func 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 | } |
no test coverage detected