-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock.go
More file actions
31 lines (28 loc) · 1.2 KB
/
Copy pathmock.go
File metadata and controls
31 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package loglayer
// discardTransport is a no-op transport used by NewMock. It accepts every entry
// and produces no output. Level filtering is irrelevant because SendToLogger
// does nothing.
type discardTransport struct{}
func (discardTransport) ID() string { return "mock" }
func (discardTransport) IsEnabled() bool { return true }
func (discardTransport) SendToLogger(TransportParams) {}
func (discardTransport) GetLoggerInstance() any { return nil }
// NewMock returns a *LogLayer that silently discards every entry. Use it in
// tests when you need to pass a logger to code under test but don't care about
// its output.
//
// The returned value is the same concrete *LogLayer type as a production
// logger, so it drops into anywhere the real one fits. All methods behave
// normally — context, metadata, child loggers, level changes — they just
// produce no output.
//
// DisableFatalExit is enabled so log.Fatal(...) in code under test does not
// terminate the test process.
//
// To assert on what was logged, use the transports/testing transport instead.
func NewMock() *LogLayer {
return New(Config{
Transport: discardTransport{},
DisableFatalExit: true,
})
}