MCPcopy
hub / github.com/op/go-logging / TestBackendFormatter

Function TestBackendFormatter

format_test.go:145–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

143}
144
145func TestBackendFormatter(t *testing.T) {
146 InitForTesting(DEBUG)
147
148 // Create two backends and wrap one of the with a backend formatter
149 b1 := NewMemoryBackend(1)
150 b2 := NewMemoryBackend(1)
151
152 f := MustStringFormatter("%{level} %{message}")
153 bf := NewBackendFormatter(b2, f)
154
155 SetBackend(b1, bf)
156
157 log := MustGetLogger("module")
158 log.Info("foo")
159 if "foo" != getLastLine(b1) {
160 t.Errorf("Unexpected line: %s", getLastLine(b1))
161 }
162 if "INFO foo" != getLastLine(b2) {
163 t.Errorf("Unexpected line: %s", getLastLine(b2))
164 }
165}
166
167func BenchmarkStringFormatter(b *testing.B) {
168 fmt := "%{time:2006-01-02T15:04:05} %{level:.1s} %{id:04d} %{module} %{message}"

Callers

nothing calls this directly

Calls 9

InitForTestingFunction · 0.85
NewMemoryBackendFunction · 0.85
MustStringFormatterFunction · 0.85
NewBackendFormatterFunction · 0.85
SetBackendFunction · 0.85
MustGetLoggerFunction · 0.85
getLastLineFunction · 0.85
InfoMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected