CaptureContextLog redirects the default fiberlog output into a fresh buffer and configures the given context format. On test cleanup, the default logger output is restored to os.Stderr and the context template is cleared. Tests that use this helper must NOT call t.Parallel() because the helper muta
(tb testing.TB, format string)
| 19 | // Tests that use this helper must NOT call t.Parallel() because the helper |
| 20 | // mutates package-global default-logger state shared across tests. |
| 21 | func CaptureContextLog(tb testing.TB, format string) *bytes.Buffer { |
| 22 | tb.Helper() |
| 23 | |
| 24 | var buf bytes.Buffer |
| 25 | fiberlog.SetOutput(&buf) |
| 26 | fiberlog.MustSetContextTemplate(fiberlog.ContextConfig{Format: format}) |
| 27 | |
| 28 | tb.Cleanup(func() { |
| 29 | fiberlog.MustSetContextTemplate(fiberlog.ContextConfig{}) |
| 30 | fiberlog.SetOutput(os.Stderr) |
| 31 | }) |
| 32 | |
| 33 | return &buf |
| 34 | } |