MCPcopy
hub / github.com/gofiber/fiber / CaptureContextLog

Function CaptureContextLog

internal/loggertest/loggertest.go:21–34  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

19// Tests that use this helper must NOT call t.Parallel() because the helper
20// mutates package-global default-logger state shared across tests.
21func 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}

Calls 1

SetOutputMethod · 0.65