()
| 83 | } |
| 84 | |
| 85 | func Example_logWithSlog() { |
| 86 | // This example demonstrates how to log an errtrace-wrapped error |
| 87 | // with the slog package. |
| 88 | // Unlike LogAttr, we're able to use any key name here. |
| 89 | logger, printLogOutput := newExampleLogger() |
| 90 | |
| 91 | if err := f1(); err != nil { |
| 92 | logger.Error("f1 failed", "my-error", err) |
| 93 | } |
| 94 | |
| 95 | printLogOutput() |
| 96 | |
| 97 | // Output: |
| 98 | // {"level":"ERROR","msg":"f1 failed","my-error":"failed\n\nbraces.dev/errtrace_test.f3\n\t/path/to/errtrace/example_trace_test.go:3\nbraces.dev/errtrace_test.f2\n\t/path/to/errtrace/example_trace_test.go:2\nbraces.dev/errtrace_test.f1\n\t/path/to/errtrace/example_trace_test.go:1\n"} |
| 99 | } |
| 100 | |
| 101 | // newExampleLogger creates a new slog.Logger for use in examples. |
| 102 | // It omits timestamps from the output to allow for output matching, |
nothing calls this directly
no test coverage detected